0

Here is my source code

#include <casadi/casadi.hpp>

int main(int argc, char** argv)
{
  casadi::SX x = casadi::SX::sym("x");

  return 0;
}

I use gcc version of 9, and complier is std=c++14(c++11, c++17: all didn't work).
I want to use Casadi library in my project but the error occurs below.
I have difficulty building and compling my code
Anyone who knows how to solve it?

Errors     << bigbot_tutorial:make /home/scpark/cps_ws/logs/bigbot_tutorial/build.make.033.log                                                                                                      
CMakeFiles/mpc_basic_node.dir/src/mpc_basic.cpp.o: In function `casadi::Sparsity::~Sparsity()':
mpc_basic.cpp:(.text._ZN6casadi8SparsityD2Ev[_ZN6casadi8SparsityD5Ev]+0x14): undefined reference to `casadi::SharedObject::~SharedObject()'
CMakeFiles/mpc_basic_node.dir/src/mpc_basic.cpp.o: In function `casadi::GenericMatrix<casadi::Matrix<casadi::SXElem> >::sym(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, long long, long long)':
mpc_basic.cpp:(.text._ZN6casadi13GenericMatrixINS_6MatrixINS_6SXElemEEEE3symERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEExx[_ZN6casadi13GenericMatrixINS_6MatrixINS_6SXElemEEEE3symERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEExx]+0x3b): undefined reference to `casadi::Sparsity::dense(long long, long long)'
CMakeFiles/mpc_basic_node.dir/src/mpc_basic.cpp.o: In function `casadi::operator<<(std::ostream&, casadi::Matrix<casadi::SXElem> const&)':
mpc_basic.cpp:(.text._ZN6casadilsERSoRKNS_6MatrixINS_6SXElemEEE[_ZN6casadilsERSoRKNS_6MatrixINS_6SXElemEEE]+0x24): undefined reference to `casadi::Matrix<casadi::SXElem>::disp(std::ostream&, bool) const'
CMakeFiles/mpc_basic_node.dir/src/mpc_basic.cpp.o: In function `casadi::GenericMatrix<casadi::Matrix<casadi::SXElem> >::sym(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, casadi::Sparsity const&)':
mpc_basic.cpp:(.text._ZN6casadi13GenericMatrixINS_6MatrixINS_6SXElemEEEE3symERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_8SparsityE[_ZN6casadi13GenericMatrixINS_6MatrixINS_6SXElemEEEE3symERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_8SparsityE]+0x36): undefined reference to `casadi::Matrix<casadi::SXElem>::_sym(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, casadi::Sparsity const&)'
CMakeFiles/mpc_basic_node.dir/src/mpc_basic.cpp.o: In function `void std::_Destroy<casadi::SXElem>(casadi::SXElem*)':
mpc_basic.cpp:(.text._ZSt8_DestroyIN6casadi6SXElemEEvPT_[_ZSt8_DestroyIN6casadi6SXElemEEvPT_]+0x14): undefined reference to `casadi::SXElem::~SXElem()'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/scpark/cps_ws/devel/.private/bigbot_tutorial/lib/bigbot_tutorial/mpc_basic_node] Error 1
make[1]: *** [CMakeFiles/mpc_basic_node.dir/all] Error 2
make: *** [all] Error 2
cd /home/scpark/cps_ws/build/bigbot_tutorial; catkin build --get-env bigbot_tutorial | catkin env -si  /usr/bin/make --jobserver-fds=3,4 -j; cd -

....................................................................................................................................................................................................
Failed     << bigbot_tutorial:make              [ Exited with code 2 ]                                                                                                                              
Failed    <<< bigbot_tutorial                   [ 1.5 seconds ]                                                                                                                                     
[build] Summary: 4 of 5 packages succeeded.                                                                                                                                                         
[build]   Ignored:   None.                                                                                                                                                                          
[build]   Warnings:  None.                                                                                                                                                                          
[build]   Abandoned: None.                                                                                                                                                                          
[build]   Failed:    1 packages failed.                                                                                                                                                             
[build] Runtime: 1.7 seconds total. 
  • My guess? You don't *link* with the actual library. Please [edit] your question to show us how you link your application. – Some programmer dude Apr 29 '22 at 08:13
  • Or your library path is incorrect. – kiner_shah Apr 29 '22 at 08:14
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Biffen Apr 29 '22 at 08:16
  • How to link the library? The installed path is **/usr/local/include/casadi**. – bigbigpark Apr 29 '22 at 08:50
  • That is the path to the *header* files. There should also be a file named something like `libcasadi.a` or `libcasadi.so` in the `/usr/local/lib` directory. You need to add an `-L` option when linking to tell the linker about the path to the library, and the `-l` (lower-case L) to tell the linker to actually link with the library. There are many tutorials all over the Internet on how to link with libraries. – Some programmer dude Apr 29 '22 at 09:57

0 Answers0