CasADI in C++: symbol lookup error - undefined symbol

44 views
Skip to first unread message

M R

unread,
Mar 27, 2023, 11:32:11 AM3/27/23
to CasADi
Hello all,

I want to include CasADI with c++ and I followed this example to include it with cmake.

I also added that flag to the CMakeLists: add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

I am not able to generate any CasADI symbols like SX or MX. When I add this line "SX a = SX::sym("a");" into my main.cpp I receive an error message when executing the generated exe.

I can compile my code in the build folder with 
1. cmake ..
2. make
and it compiles. When executing the executable, I am running into the following error: 
./untitled: symbol lookup error: ./untitled: undefined symbol: _ZN6casadi6MatrixINS_6SXElemEE4_symERKSsRKNS_8SparsityE

Does anybody knows a solution for that kind of problems?

Thank you very much for any help! Below is my code :)


My file structure:
  • CMakeLists.txt
  • main.cpp
  • build
    • ... all build files
    • untitled (exe)
  • external
    • CMakeLists.txt
The included code:

main.cpp:
#include <casadi/casadi.hpp>

using namespace casadi;
using namespace std;

int main()
{
casadi_printf("This works! \n");
SX a = SX::sym("a");
return 0;
}
CMakeLists.txt: 
cmake_minimum_required(VERSION 3.10)
project(untitled)

set(CMAKE_CXX_STANDARD 17)

# some default target
add_executable(untitled main.cpp)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
# Configure and build external project
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/external)
execute_process(
COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}/external
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/external
)
execute_process(
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/external
)

# find and link externals
find_package(casadi REQUIRED HINTS ${CMAKE_BINARY_DIR}/external/external/casadi/src/casadi-3.5.5/casadi)
target_link_libraries(untitled casadi)

external/CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(external)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
include(ExternalProject)
ExternalProject_Add(
casadi-3.5.5
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
PREFIX ${CMAKE_BINARY_DIR}/external/casadi)




Reply all
Reply to author
Forward
0 new messages