使用 cygwin 编译 boost 程序的问题

发布于 2024-08-01 21:05:26 字数 1028 浏览 2 评论 0原文

更新:找到了一种使其编译的方法,见下文。

您好,我在 cygwin 下编译 boost 程序时遇到问题。 我已经从 cygwin 项目的 setup.exe 安装了默认的 boost 和 g++ 软件包。

在我的 Linux 系统上,我可以使用以下命令编译程序 reg.cpp:

g++ -I/usr/include/boost -lboost_regex -o reg reg.cpp

在 cygwin 上,我必须稍微编辑一下:

g++ -I/usr/include/boost-1_33_1 -lboost_regex-gcc-mt -o reg reg.cpp

问题是 cygwin 版本导致链接器拉出一百万个未定义的引用错误。 尝试使用 boost 测试框架库时也会发生同样的事情。

链接器正在查找 boost_regex-gcc-mt,但它似乎与包含文件不匹配。 这是第一个链接器错误:

undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'

如何编译

我找到了一个解决方案这里为了编译,我做了以下操作:

g++ -I/usr/include/boost-1_33_1 reg.cpp -o reg -lboost_regex-gcc-mt

根据帖子,它与链接器顺序有关。 有人知道为什么这在 cygwin 中很重要,但在现代 Linux 中却不重要吗?

UPDATE: Found a way to make it compile, see below.

Hello, I'm having issues compiling boost programs under cygwin. I've installed the default boost and g++ packages from the cygwin project's setup.exe.

On my Linux systems, I can compile a program reg.cpp using the following:

g++ -I/usr/include/boost -lboost_regex -o reg reg.cpp

On cygwin I have to edit this just a bit:

g++ -I/usr/include/boost-1_33_1 -lboost_regex-gcc-mt -o reg reg.cpp

The problem is that the cygwin version causes the linker to pull up a million undefined reference errors. The same thing happens trying to use the boost test framework libraries.

The linker is finding boost_regex-gcc-mt, but it doesn't appear to match the include file. Here's the first linker error:

undefined reference to `boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)'

HOW TO COMPILE

I found a solution here To compile, I did the following:

g++ -I/usr/include/boost-1_33_1 reg.cpp -o reg -lboost_regex-gcc-mt

According to the post, it has something to do with linker order. Anybody got a clue why this matters in cygwin but not modern Linux?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿港巷口少年归 2024-08-08 21:05:27

事实证明,链接器传统上是从右到左处理库的。 大多数链接器不关心库的放置,但 cygwin 关心。 所以 boost_regex 库必须放在最后。

It turns out that linkers traditionally process libraries from right to left. Most linkers don't care about library placement, but cygwin does. So the boost_regex library has to go at the end.

早乙女 2024-08-08 21:05:27

如果您查看 boost 文档的示例(入门):

Cygwin 上的命令应该是:(

g++ -c example.cpp
g++ -o example.exe example.o -lboost_regex-mt

该库包含在 cpp 文件之后。)
错误的:

g++ -o example.exe -lboost_regex-mt example.o 

If you look at the example of the boost documentation (Getting Started):

The command on Cygwin should be :

g++ -c example.cpp
g++ -o example.exe example.o -lboost_regex-mt

(The library is included AFTER the cpp file.)
WRONG:

g++ -o example.exe -lboost_regex-mt example.o 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文