Skip to content

Create a Project - CPP Examples

In this guide you will learn how to create a separate project from scratch using the CPP SDK.

Prerequisite

It is required that you complete the Environment Setup - CPP Examples guide before starting this guide.

Create a Visual Studio project from scratch

vstudio Create - example CPP screenshot

Start Visual Studio and in the
What would you like to do? dialog,
select Create a new project

vstudio menu Close - example CPP screenshot

or, alternatively, if Visual Studio is already started, close the current project, if any is open:
from the menu, select

File->Close Solution

and then, from the menu select

File->New->Project...

vstudio Empty Project - example CPP screenshot

In the Create a new project dialog,
select Empty Project and click Next

vstudio Configure Project - example CPP screenshot

In the Configure your new project dialog,
name your project, Project1 for example, and set the location to C:\MAGICLANE
You can give the project any name, but to avoid problems, the name should not contain spaces;
then click Create.

vstudio Created Project - example CPP screenshot

The new project was created.
In the top toolbar, select Debug and x64
In this documentation, this project will be referred to as Project1
Note that a new directory, C:\MAGICLANE\Project1\ was created.

Copy required files

Copy the following files

ApiLogger.h
Environment.cpp
Environment.h
Listeners.cpp
Listeners.h
OpenGLContext.cpp
OpenGLContext.h
Timer.cpp
Timer.h
from C:\MAGICLANE\maps-sdk-examples-for-cpp-master\Examples\
to C:\MAGICLANE\Project1\
Add the headers (.h files) and the source (.cpp files) shown above to the project, as described below.
These files must be present in any application using the CPP SDK.

vstudio project Add item - example CPP screenshot

Right-click on Header Files, and select Add->Existing Item...

Browse to the
C:\MAGICLANE\Project1
directory and
select the 5 header (.h) files shown above (hold down the Ctrl key as you click on each header file)
then click Add

Right-click on Source Files, and select Add->Existing Item...

select the 4 source (.cpp) files shown above
then click Add

Copy the file

CenterMap.cpp

from C:\MAGICLANE\maps-sdk-examples-for-cpp-master\Examples\D3Scene\CenterMap\
to C:\MAGICLANE\Project1\
Right-click on Source Files, and select Add->Existing Item...
select CenterMap.cpp then click Add

This file is the starting point of the new application.

Create this directory:

C:\MAGICLANE\SDK\3rdParty\GLFW\lib\x64\

Copy GLFW.lib from
C:\MAGICLANE\maps-sdk-examples-for-cpp-master\BUILD_WIN\Maps-SDK-Examples-for-Cpp\Lib\x64\Debug\
to C:\MAGICLANE\SDK\3rdParty\GLFW\lib\x64\

This is the GLFW3 graphics library which was built in the prerequisite guide.

Configure the project

vstudio project Properties - example CPP screenshot

Right-click on Project1 and select Properties

Verify these settings at the top of the dialog are as follows:

Configuration: All Configurations Platform: x64

vstudio project include - example CPP screenshot

In the left panel, select Configuration Properties->C/C++->General
In the right panel, select Additional Include Directories
$(SolutionDir)..\SDK\Include
$(SolutionDir)..\SDK\3rdParty\ANGLE\include
$(SolutionDir)
$(SolutionDir)..\maps-sdk-examples-for-cpp-master\Examples\3rdParty\GLFW\deps
$(SolutionDir)..\maps-sdk-examples-for-cpp-master\Examples\3rdParty\GLFW\include

This configures the locations of include files and dependencies, used for building the project, relative to the solution directory, which is C:\MAGICLANE\Project1\ unless you changed it.

vstudio project Preprocessor - example CPP screenshot

In the left panel, select Configuration Properties->C/C++->Preprocessor
In the right panel, select Preprocessor Definitions

and add:

WIN64;_WINDOWS;_CRT_SECURE_NO_WARNINGS

This preprocessor definition is required for a successful build: _CRT_SECURE_NO_WARNINGS

vstudio project lib directories - example CPP screenshot

In the left panel, select Configuration Properties->Linker->General
In the right panel, select Additional Library Directories
$(SolutionDir)..\SDK\Lib
$(SolutionDir)..\SDK\3rdParty\ANGLE\lib\x64
$(SolutionDir)..\SDK\3rdParty\GLFW\lib\x64

This configures the locations of libraries used for building the project, relative to the solution directory, which is C:\MAGICLANE\Project1\ unless you changed it.

The top directory contains the Magic Lane SDK.
The second directory contains the OpenGL graphic libraries.
The third directory contains the GLFW3 graphic window library built in the prerequisite guide, see link at the top of this document.

vstudio project dependencies - example CPP screenshot

In the left panel, select Configuration Properties->Linker->Input
In the right panel, select Additional Dependencies
GEMStatic_d.lib
GLFW.lib
libEGL.dll.lib
libGLESv2.dll.lib
Ws2_32.lib
Shlwapi.lib
Kernel32.lib
Psapi.lib

Add the above libraries. The first one is the Magic Lane SDK, the next 3 are 3rd party graphic libraries, and the last 4 are system libraries.

This configures the names of actual libraries (dependencies) used for building the project, relative to the solution directory, which is C:\MAGICLANE\Project1\ unless you changed it.

vstudio project output directory - example CPP screenshot

In the left panel, select Configuration Properties->General
In the right panel, select Output Directory

and set it to:

$(SolutionDir)..\BUILD_WIN\$(SolutionName)\Bin\$(Platform)\$(Configuration)\

This configures the name of the directory where the built executable of this project, and all other Magic Lane projects, will be located:
C:\MAGICLANE\BUILD_WIN\
Note that the Magic Lane SDK, all your Magic Lane projects, and the BUILD_WIN directory, containing the built executables, are all located under C:\MAGICLANE\ unless you changed it.
Example:
C:\MAGICLANE\SDK\
C:\MAGICLANE\Project1\
C:\MAGICLANE\Project2\
C:\MAGICLANE\ProjectN\
C:\MAGICLANE\BUILD_WIN\
In the right panel, select Intermediate Directory

and set it to:

$(SolutionDir)..\BUILD_WIN\$(SolutionName)\Obj\$(Platform)\$(Configuration)\$(ProjectName)\

The directory containing the object files resulting from the compile.

vstudio project build events - example CPP screenshot

In the left panel, select Configuration Properties->Build Events->Post-Build Event
In the right panel, select Command Line

and add:

xcopy /D /Q /Y "$(SolutionDir)..\SDK\3rdParty\ANGLE\bin\$(Platform)\*.dll" "$(OutDir)"

This will copy the dll libraries to the directory where the compiled executable is located, because that is the easiest way for the executable to find its dlls at runtime.

Set your API key token

Set your API key token in the std::string projectApiToken = ""; string in the main() function, before env.InitSDK() is called.