Boost Libraries:无法在MAC OS X上链接正则表达式库

时间:2010-09-29 16:51:40

标签: regex macos boost linker

我正在尝试使用Boost Libraries ......但无济于事。我尝试按照Boost网站上的入门教程(针对Unix变体),但在此过程中遇到了问题。

我将库编译到Downloads文件夹中的目录中:

/Users/myUsername/Downloads/boostCompiled

当我使用库的完整路径时...示例程序(在Boost网站上给出)编译并链接正常。

g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ /Users/myUsername/Downloads/boostCompiled/lib/libboost_regex.a

但是,当我尝试链接使用-L和-l选项时......它失败了......

g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l boost_regex

ld: library not found for -lboost_regex
collect2: ld returned 1 exit status

g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l libboost_regex

ld: library not found for -llibboost_regex
collect2: ld returned 1 exit status

g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l regex

ld: library not found for -lregex
collect2: ld returned 1 exit status

我的shell是bash ...我已将DYLD_LIBRARY_PATH设置为以下内容:

export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/Users/myUsername/Downloads/boostCompiled/lib

看来我没有使用正确的名称链接(使用-l)选项。有人可以帮忙!提前谢谢!

1 个答案:

答案 0 :(得分:1)

  • -L/Users/myUsername/Downloads/boostCompiled/lib/之间不应有空格

  • 确保在libboost_regex.a中编译/Users/myUsername/Downloads/boostCompiled/lib

然后这应该有效:

g++ -o boostTesting boostTesting.cpp -I/Users/myUsername/Downloads/boostCompiled/include/ -L/Users/myUsername/Downloads/boostCompiled/lib/ -lboost_regex