artery
artery copied to clipboard
Adding a library to my scenario
Hello,
I'm trying to use the Pytorch C++ library "libtorch" in my scenario. However, I'm struggling adding this later to my scenario. The issue is that when I want to link the library to artery or to my scenario's target using "target_link_libraries(myTarget "${TORCH_LIBRARIES}")" in the CMakefiles I have the following error:
CMake Error at ..... (the CMake file in my scenario): cannot specify link libraries for target myTarget "libtorch/lib/libc10.so; libtorch/lib/libkinto.a" which is not built by this project.
Is there any way to link an external library to artery ? Thanks.
Linking external libraries to Artery is not different to any other CMake project. Since your TORCH_LIBRARIES
variable contains a list of libraries, you should not put double quotes around the variable name when passing it to target_link_libraries
. Right now, CMake tries to find a single file named "libtorch/lib/libc10.so; libtorch/lib/libkinto.a" which does not exist.
Hello,
Thanks for your answer, unfortunately the issue wasn't with the double quotes, it works with the double quotes as without them if there is only one variable.
The issue was with the visibility of the Target of the scenario. The solution is to indicate that the target is private.
Here is the complete configuration that worked for me : set(CMAKE_PREFIX_PATH the_path_of_libtorch_in your_pc) find_package(Torch REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
target_link_libraries(target PRIVATE "${TORCH_LIBRARIES}") set_property(TARGET target PROPERTY CXX_STANDARD 14)
Thanks for all.
Hey @riebl,
I have an Undefined Symbol error when I build my scenario, the problem is that this Undefined Symbol is not related to any of my scenario's files its an omnetpp symbol. And this error happens when I add the libtorch library (I will explain):
All was working fine for me when I was working on a virtual machine, but I wanted to use my GPU so I copied all my code and Artery to a Linux machine with a GPU.
I followed all the installation steps of the Artery framework as usual. I added my scenario that contains in its CMakeFiles this code (link to libtorch):
set(CMAKE_PREFIX_PATH` the_path_of_my_libtorch_dir)
find_package(Torch REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
target_link_libraries(target PRIVATE "${TORCH_LIBRARIES}")
set_property(TARGET target PROPERTY CXX_STANDARD 14)
I build artery and all scenarios work perfectly except mine because of the code I added. But as I said everything works fine in my virtual machine.
I got this error of Undefined Symbol:
<!> Error: Cannot load library 'WorkingDir/artery/build/scenarios/my-scenario-dir/libartery_myTarget.so': WorkingDir/artery/build/scenarios/my-scenario-dir/libartery_myTarget.so: undefined symbol: _ZNK7omnetpp7cModule11getFullPathEv
And the symbol means: omnetpp::cModule::getFullPath() const
I think it is a compilation error related to c++ standards (c++11 and c++14), so I checked the "so" library and found this: In a scenario without the libtorch code, we have these symbols in the ".so" file:
U _ZNK7omnetpp7cModule11getFullNameEv
U _ZNK7omnetpp7cModule11getFullPathB5cxx11Ev
W _ZNK7omnetpp7cObject11getFullNameEv
U _ZNK7omnetpp7cObject11getFullPathB5cxx11Ev
In a scenario with the libtorch code, we have these symbols in the ".so" file:
U _ZNK7omnetpp7cModule11getFullNameEv
U _ZNK7omnetpp7cModule11getFullPathEv
W _ZNK7omnetpp7cObject11getFullNameEv
U _ZNK7omnetpp7cObject11getFullPathEv
In the scenario with the libtorch code from my virtual machine, where all was working, we have these symbols in the ".so" file:
U _ZNK7omnetpp7cModule11getFullNameEv
U _ZNK7omnetpp7cModule11getFullPathB5cxx11Ev
W _ZNK7omnetpp7cObject11getFullNameEv
U _ZNK7omnetpp7cObject11getFullPathB5cxx11Ev
The symbol "U _ZNK7omnetpp7cModule11getFullPathB5cxx11Ev" means: omnetpp::cModule::getFullPath[abi:cxx11]() const
I tried to:
- compile all the artery code with C++14
- download a pre cxx11 version of libtorch
- recompile omnet++
- all I know
And nothing same problem.
I think the problem is in the configuration of the new machine or in building omnet++ (I tried in other machines and nothing same issue). Can you please help me solve this issue ?
If you need any other information tell me.
Cordially.
Sorry for my late reply. I would try to compile OMNeT++ with C++14, though I wonder why the symbol names would have changed from C++11 to C++14. You can add the compile flag for C++14 mode to the configure.user file in the OMNeT++ root directory as CXXFLAGS variable.
Hi,
Yes, this is what I exactly did with OMNeT++, then I had the same issue with vanetza and other artery dependencies. I solved it with vanetza and boost the same way I did with OMNeT++. Then at some point, I gave up because I couldn't compile one of the dependencies with C++14.
But the main question in this Issue is why the integration of libtorch work fine with my first virtual machine. And it doesn't work in other machines: WSL2 (same ubuntu version), a physical device with the same Ubuntu version, and another virtual machine with the same configuration.
Cordially.