我正在尝试编译网站上提供的示例问题(对于C ++)并且遇到问题: NMead.cpp是我的程序。我用g ++编译它
g++ -g -O2 -I/usr/local/Cellar/nlopt/2.4.2/include -L/usr/local/Cellar/nlopt/2.4.2/lib -o NMead -lm -lnlopt NMead.cpp -v
生成的消息是:
Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin14/4.9.3/lto-wrapper Target: x86_64-apple-darwin14 Configured with: /opt/local/var/macports/build/_opt_mports_dports_lang_gcc49/gcc49/work/gcc-4.9.3/configure
--prefix=/opt/local --build=x86_64-apple-darwin14 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc49 --includedir=/opt/local/include/gcc49 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.9 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.9 --with-gxx-include-dir=/opt/local/include/gcc49/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --disable-isl-version-check --with-cloog=/opt/local --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc49 4.9.3_0' Thread model: posix gcc version 4.9.3 (MacPorts gcc49 4.9.3_0) COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.5' '-g' '-O2' '-I' '/usr/local/Cellar/nlopt/2.4.2/include' '-L/usr/local/Cellar/nlopt/2.4.2/lib' '-o' 'NMead' '-v' '-shared-libgcc' '-mtune=core2' /opt/local/libexec/gcc/x86_64-apple-darwin14/4.9.3/cc1plus -quiet -v
-I /usr/local/Cellar/nlopt/2.4.2/include -D__DYNAMIC__ NMead.cpp -fPIC -feliminate-unused-debug-symbols -quiet -dumpbase NMead.cpp -mmacosx-version-min=10.10.5 -mtune=core2 -auxbase NMead -g -O2 -version -o /var/folders/zs/t_yzdt597z3cfwlr36hr78gw002vb6/T//cc5WiU5P.s GNU C++ (MacPorts gcc49 4.9.3_0) version 4.9.3 (x86_64-apple-darwin14) compiled by GNU C version 4.9.3, GMP version 6.0.0, MPFR version
3.1.3, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/../../../../../x86_64-apple-darwin14/include"
#include "..." search starts here:
#include <...> search starts here: /usr/local/Cellar/nlopt/2.4.2/include /opt/local/include/gcc49/c++/ /opt/local/include/gcc49/c++//x86_64-apple-darwin14 /opt/local/include/gcc49/c++//backward /opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/include /opt/local/include /opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/include-fixed /usr/include /System/Library/Frameworks /Library/Frameworks End of search list. GNU C++ (MacPorts gcc49 4.9.3_0) version 4.9.3 (x86_64-apple-darwin14) compiled by GNU C version 4.9.3, GMP version
6.0.0, MPFR version 3.1.3, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 0ca13fbc9617161ec7a95e943acdf57e COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.5' '-g' '-O2' '-I' '/usr/local/Cellar/nlopt/2.4.2/include' '-L/usr/local/Cellar/nlopt/2.4.2/lib' '-o' 'NMead' '-v' '-shared-libgcc' '-mtune=core2' /opt/local/bin/as -v -I /usr/local/Cellar/nlopt/2.4.2/include -arch x86_64
-force_cpusubtype_ALL -o /var/folders/zs/t_yzdt597z3cfwlr36hr78gw002vb6/T//cclPMJVL.o /var/folders/zs/t_yzdt597z3cfwlr36hr78gw002vb6/T//cc5WiU5P.s Apple Inc version cctools-870, GNU assembler version 1.38 COMPILER_PATH=/opt/local/libexec/gcc/x86_64-apple-darwin14/4.9.3/:/opt/local/libexec/gcc/x86_64-apple-darwin14/4.9.3/:/opt/local/libexec/gcc/x86_64-apple-darwin14/:/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/:/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/ LIBRARY_PATH=/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/:/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/../../../:/usr/lib/ COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.5' '-g' '-O2' '-I' '/usr/local/Cellar/nlopt/2.4.2/include' '-L/usr/local/Cellar/nlopt/2.4.2/lib' '-o' 'NMead' '-v' '-shared-libgcc' '-mtune=core2' /opt/local/libexec/gcc/x86_64-apple-darwin14/4.9.3/collect2 -dynamic
-arch x86_64 -macosx_version_min 10.10.5 -weak_reference_mismatches non-weak -o NMead -L/usr/local/Cellar/nlopt/2.4.2/lib
-L/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3 -L/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/../../.. -lnlopt /var/folders/zs/t_yzdt597z3cfwlr36hr78gw002vb6/T//cclPMJVL.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v -idsym -dsym collect2 version 4.9.3 /opt/local/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.10.5 -weak_reference_mismatches non-weak
-o NMead -L/usr/local/Cellar/nlopt/2.4.2/lib -L/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3 -L/opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3/../../.. -lnlopt /var/folders/zs/t_yzdt597z3cfwlr36hr78gw002vb6/T//cclPMJVL.o -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v @(#)PROGRAM:ld PROJECT:ld64-242 configured to support archs: i386 x86_64 x86_64h armv6 armv7 armv7s armv7m armv7k arm64 Library search paths: /usr/local/Cellar/nlopt/2.4.2/lib /opt/local/lib/gcc49/gcc/x86_64-apple-darwin14/4.9.3 /opt/local/lib/gcc49 /usr/lib /usr/local/lib Framework search paths: /Library/Frameworks/ /System/Library/Frameworks/ /opt/local/bin/nm -n /var/folders/zs/t_yzdt597z3cfwlr36hr78gw002vb6/T//cclPMJVL.o dsymutil NMead
当我尝试运行生成的可执行文件时:
./NMead
我收到以下错误:
dyld:未加载库: /usr/local/opt/nlopt/lib/libnlopt_cxx.0.dylib参考自: /Users/dlekshmi/Documents/workspace/TUTORIALS/./NMead原因:图片 未找到Trace / BPT陷阱:5
我怀疑是因为某些原因,它正在寻找图书馆错误的地方。我跑了
otool -L ./NMead
并且生成的消息表明它确实是:
./ NMead: /usr/local/opt/nlopt/lib/libnlopt_cxx.0.dylib(兼容版本9.0.0,当前版本9.2.0) /opt/local/lib/libgcc/libstdc++.6.dylib(兼容版本7.0.0,当前版本7.21.0) /usr/lib/libSystem.B.dylib(兼容版本1.0.0,当前版本1213.0.0) /opt/local/lib/libgcc/libgcc_s.1.dylib(兼容版本1.0.0,当前版本1.0.0)
我是C ++和nlopt的新手,我不确定我做错了什么。