Compile c++ code by cmake, using remote API

Typically: "How do I... ", "How can I... " questions
Post Reply
3mayuge3
Posts: 10
Joined: 22 Oct 2018, 08:12

Compile c++ code by cmake, using remote API

Post by 3mayuge3 » 11 Oct 2019, 06:31

Hello

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*)"127.0.0.1", 19997, true, true, 5000, 5);
    std::cout << clientID << std::endl;

    std::thread th(th_sample);
    th.join();

    return 0;
}
CMakeLists.txt:

Code: Select all

cmake_minimum_required(VERSION 3.1.0)

#set project name
project(tamesi2 CXX)

find_package(Threads REQUIRED)

# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)

# 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)

#bild
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

(omitted)

[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.
tamesi2/
├ build/ - CMakeFIles/ etc.
├ include/
├ remoteApi/
├ tamesi2.cpp
├ CMakeLists.txt

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

fferri
Posts: 396
Joined: 09 Sep 2013, 19:28

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

Post by fferri » 17 Oct 2019, 07:40

Hi,

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

Cheers

3mayuge3
Posts: 10
Joined: 22 Oct 2018, 08:12

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

Post by 3mayuge3 » 17 Oct 2019, 08:11

Hello,

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

Post Reply