无法链接ipopt库(MacOS Mojave上为C ++)

时间:2019-06-14 14:13:03

标签: c++ macos ipopt

我想在MacOS Mojave的echo "<img src='$file_name'>";软件中使用ipoptcppad

编译停止,如下所示。

为什么编译并且链接器仍然失败。

  

有人可以帮忙吗?

我在C++Xcode上尝试过。两个IDE给我相同的错误。我还经常使用brew重新安装cppad和ipconfig。

CLion似乎有效。我可以包含以下标题:

include_paths
#include <cppad/cppad.hpp>
#include <cppad/ipopt/solve.hpp>

更新:此处更改为-v选项后,Undefined symbols for architecture x86_64: "Ipopt::IpoptApplication::IpoptApplication(bool, bool)", referenced from: void CppAD::ipopt::solve<CppAD::vector<double>, FG_eval>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, CppAD::vector<double> const&, CppAD::vector<double> const&, CppAD::vector<double> const&, CppAD::vector<double> const&, CppAD::vector<double> const&, FG_eval&, CppAD::ipopt::solve_result<CppAD::vector<double> >&) in MPC.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 内容的前半部分:

CMakeOutput.log

1 个答案:

答案 0 :(得分:0)

我按如下方式工作:

发生问题,因为我没有在CMakeLists.txt中正确包含ipopt库。我通过以下Make配置解决了该问题:

cmake_minimum_required(VERSION 3.14)
project(ProjectName)

set(CMAKE_CXX_STANDARD 17)

include_directories(/usr/local/include)
link_directories(/usr/local/lib)

set(SOURCE_FILES unmanned.cpp mpc.cpp)

add_executable(ProjectName ${SOURCE_FILES})
target_link_libraries(ProjectName ipopt)