Page 1 of 1

Compile c++ code by cmake, using remote API

Posted: 11 Oct 2019, 06:31
by 3mayuge3

I'm trying to control simulation by remote API, c++, at ubuntu. So I made CMakeLists.txt and do "cmake .." and "make".

The code is:

Code: Select all

#include <iostream>
#include <thread>

extern "C" {
#include "extApi.h"

void th_sample() {
    std::cout << "thread id: " << std::this_thread::get_id() << std::endl;

int main() {
    int clientID = simxStart((simxChar*)"", 19997, true, true, 5000, 5);
    std::cout << clientID << std::endl;

    std::thread th(th_sample);

    return 0;

Code: Select all

cmake_minimum_required(VERSION 3.1.0)

#set project name
project(tamesi2 CXX)

find_package(Threads REQUIRED)

# Enable C++11

# vrep
include_directories(tamesi2 remoteApi)
include_directories(tamesi2 include)

add_definitions (-DNON_MATLAB_PARSING)
add_definitions (-DMAX_EXT_API_CONNECTIONS=255)
add_definitions (-DDO_NOT_USE_SHARED_MEMORY)

add_executable (tamesi2 tamesi2.cpp remoteApi/extApi.c remoteApi/extApiPlatform.c)

target_link_libraries(tamesi2 Threads::Threads)

But the error came back. "tamesi2" is the project and c++ code name.

Code: Select all


[100%] Linking CXX executable tamesi2
CMakeFiles/tamesi2.dir/tamesi2.cpp.o: In function `main':
tamesi2.cpp:(.text+0x146): undefined reference to `simxStart'
collect2: error: ld returned 1 exit status
CMakeFiles/tamesi2.dir/build.make:94: recipe for target 'tamesi2' failed
make[2]: *** [tamesi2] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/tamesi2.dir/all' failed
make[1]: *** [CMakeFiles/tamesi2.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Ubuntu's version is 16.04 and VREP's version is 3.5.0.
My directory is as follows.
├ build/ - CMakeFIles/ etc.
├ include/
├ remoteApi/
├ tamesi2.cpp
├ CMakeLists.txt

Do you have any idea? Do you know what problem is?
Thank you.

Re: Compile c++ code by cmake, using remote API

Posted: 17 Oct 2019, 07:40
by fferri

try changing project(tamesi2 CXX) to project(tamesi2) (or project(tamesi2 C CXX)) in your CMakeLists.txt.


Re: Compile c++ code by cmake, using remote API

Posted: 17 Oct 2019, 08:11
by 3mayuge3

Thank you for your reply! And I changed project(tamesi2 CXX) to project(tamesi2 C CXX) and it worked correctly!