Skip to content

Creating MEL Projects

Evan Pezent edited this page Feb 18, 2019 · 15 revisions

With CMake

Since you already have CMake installed, here's a typical C++ project folder structure and CMakeLists.txt to get you started:

my_project            # top level of your project
├── bin               # conventionally where compiled binaries (applications) go
├── build             # conventionally where building occurs
├── include           # where your header files live
    ├── MyClass.hpp
    ├── ...
├── src               # where your source files live
    ├── MyClass.cpp
    ├── ...
    ├── main.cpp
├── CMakeLists.txt    # your top-level CMakeLists.txt

The CMakeLists.txt would then look like this:

cmake_minimum_required(VERSION 3.7)
# enable C++11
set(CMAKE_CXX_STANDARD 11)
# create project
project(MyProject)
# set binary output location (optional, but recommended)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
# include directories (your includes and MEL's)
include_directories("include" "/path/to/.../MEL/include")
# indicate where MEL.lib is
link_directories("/path/to/.../MEL/lib")
# create application
add_executable(MyApp include/MyClass.hpp src/MyClass.cpp src/main.cpp)
# link MEL
target_link_libraries(MyApp MEL)

You can save yourself some time by downloading the provided project template.

Note: If you built MEL statically, your project MUST define the preprocessor variable MEL_STATIC (e.g. by adding add_definitions(-DMEL_STATIC) to your own CMakeLists.txt). You will have to manually link your project against all of the external libraries MEL links against. To figure out which libraries are required, consult MEL's CMakeLists.txt.

Finally, to build your project open a command prompt at the top level of your project directory and run:

cd build                         # change directory to ./build
cmake ..   -G "GENERATOR STRING" # call cmake with same generator used for MEL

Note: If you are compiling for NI embedded systems (myRIO/cRIO), don't forget to set CMAKE_TOOLCHAIN_FILE when calling CMake on your project!

That's it! Now you can proceed to compile your project with the appropriate software. Remember, you should use the same compiler/generator that compiled MEL and MEL.dll or libMEL.so should be visible by your application if you built MEL as a dynamic library.

Manual Visual Studio Setup (Windows Only)

Click to Expand

Wait!: Why aren't you just using the CMake template above?! CMake will automatically generate Visual Studio .sln solution files for you, sparing you of the tedious steps that follow. Once CMake generates the .sln file, you can use the Visual Studio IDE as you normally would.

First create a new Visual Studio solution and project. Go to File > New > Project. Choose Win32 Console Application and give your Project and Solution a name. In the following wizard, uncheck Precompiled Headers (unless you know what they are and want to use them).

Right-click your project in the Solution Explorer and select Properties. Set Configuration and Platform to the same configuration MEL was built with (either Release/Debug and x86/x64).

Now make the following changes/additions:

  • C/C++ > General > Additional Include Directories
    • append: C:\path\to\...\MEL\include;
  • Linker > General > Additional Library Directories
    • append: C:\path\to\...\MEL\build\{config};
  • Linker > Input > Additional Dependencies
    • append: MEL.lib;

where {config} is either Release or Debug. Note that if you built both configurations of MEL, you can set up both in Visual Studio be repeating the steps above but with the other Configuration selected.

You should now be ready start your project. Make sure you are in the correct Configuration/Platform before you build your project. Finally, ensure that MEL.dll will be visible by your executable by copying it to the location Visual Studio outputs your .exe upon build completion.

Note: If you built MEL statically, your project MUST define the preprocessor variable MEL_STATIC (append MEL_STATIC; to Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions). You will have to manually link your project against all of the external libraries MEL links against. To figure out which libraries are required, consult MEL's CMakeLists.txt.

Clone this wiki locally