【问题标题】:C++ Boost on linux via Netbeans remote developement: undefined reference to boost::filesystem::path::codecvt()通过 Netbeans 远程开发在 Linux 上进行 C++ Boost:未定义对 boost::filesystem::path::codecvt() 的引用
【发布时间】:2023-03-26 04:58:01
【问题描述】:

所以我在 windows7 上安装了 Netbeans,并使用 samba 配置了 Ubuntu 机器,以共享我拥有源代码和 boost 库的开发目录。 我编译了 boost 库,以便能够链接到 boost_filesystem,但是当我尝试编译应用程序时仍然出现此错误:

Copying project files to /home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/ at nms@ophelia.tele2.net
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/Z/mr_deamon'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/mr_deamon
make[2]: Entering directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-     Windows-x86_64/Z/mr_deamon'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/mr_deamon.o.d"
g++    -c -g -I/opt/mail-relay/mr_deamon/boost_1_55_0 -I/opt/mail-relay/mr_deamon/mysql_connector_cpp/include -MMD -MP -MF "build/Debug/GNU-Linux-x86/mr_deamon.o.d" -o build/Debug/GNU-Linux-x86/mr_deamon.o mr_deamon.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++     -o dist/Debug/GNU-Linux-x86/mr_deamon build/Debug/GNU-Linux-x86/mr_deamon.o -L/opt/mail-relay/mr_deamon/mysql_connector_cpp/lib -L/opt/mail-relay/mr_deamon/boost_1_55_0/bin.v2/libs -lmysqlcppconn-static -lmysqlclient -lboost_system -lboost_filesystem
build/Debug/GNU-Linux-x86/mr_deamon.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
/opt/mail-relay/mr_deamon/boost_1_55_0/boost/filesystem/operations.hpp:447: undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&,   boost::system::error_code*)'
build/Debug/GNU-Linux-x86/mr_deamon.o: In function `path<char*>':
/opt/mail-relay/mr_deamon/boost_1_55_0/boost/filesystem/path.hpp:139: undefined reference to `boost::filesystem::path::codecvt()'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/mr_deamon] Error 1
make[2]: Leaving directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/Z/mr_deamon'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/nms/.netbeans/remote/ophelia.tele2.net/t2003915-Windows-x86_64/Z/mr_deamon'
make: *** [.build-impl] Error 2


BUILD FAILED (exit value 2, total time: 2s)

我认为我的链接是正确的。 下面是程序代码:

#include <iostream>
#include <boost/filesystem.hpp>
//using namespace std;
using namespace boost::filesystem;
int main(int argc, char**argv)
{
    std::cout << file_size(argv[0]);

    return EXIT_SUCCESS;
}

sql 部分在链接和所有方面都可以正常工作,但仅包括 boost 文件系统就足以导致构建错误,无法了解如何在 windows 到 Linux 上使用 netbeans 进行远程开发。我做错了什么?

不使用 netbeans 的新尝试,仅在 Ubuntu 上使用来自 Boost 文件系统 link 的示例... 并使用编译命令: g++ -pthread mr.cpp -lboost_filesystem-mt -lboost_system-mt 输出是 /tmp/ccIZaqeX.o: 在函数boost::filesystem::file_size(boost::filesystem::path const&)': mr.cpp: (.text._ZN5boost10filesystem9file_sizeERKNS0_4pathE[boost::filesystem::file_size(boost::filesystem::path const&)]+0x19): undefined reference toboost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)' /tmp/ccIZaqeX.o:在函数boost::filesystem::path::path<char*>(char* const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<char*>::type>, void>::type*)': mr.cpp: (.text._ZN5boost10filesystem4pathC2IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE[_ZN5boost10filesystem4pathC5IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE]+0x22): undefined reference toboost::filesystem::path::codecvt()' collect2: ld 返回 1 个退出状态

我不明白..

【问题讨论】:

  • 我刚刚添加了 -lboost_system ,它消除了其他错误消息,但 boost_filesystem 仍然抱怨。

标签: c++ ubuntu boost netbeans remote-server


【解决方案1】:

我昨天也遇到了同样的问题:

我是如何解决的:

首先:如果您通过源代码安装 Boost,请确保将其编译为您在 netbeans 使用的正确编译器工具集。例如,我使用 MinGW @ Windows 8 Boost/MingW 对其进行了测试。

第二:在Netbeans(我用的是7.4版本)中,我手动添加了我想要的库:

项目属性>链接器>库>添加库>选择.a 文件。

编辑:

此链接可能有用:undefined reference with boost when I try to compile

【讨论】:

  • 我在 linux box 和 netbeans 的 remotehost 工具链中都使用了 g++。结果编译的boost库位于boost_1_55_0/bin.v2/....中,并且该目录与samba共享,如您所说,我在netbeans中选择了那些.a库,您可以在我发布的构建日志中看到它们。我仍然得到同样的错误。
  • 你添加了 boost_system 文件吗?我只看到'-lmysqlcppconn-static -lmysqlclient -lboost_filesystem'
  • 是的,我添加了它,它解决了构建日志中的其他异常,但此消息不断出现:build/Debug/GNU-Linux-x86/mr_deamon.o: In function path&lt;char*&gt;': /opt/mail-relay/mr_deamon/boost_1_55_0/boost/filesystem/path.hpp:139: undefined reference to boost ::文件系统::路径::codecvt()'
  • 请复制Project Properties &gt; Linker &gt; Libraries的内容。事先,我在某处读到需要为某些环境添加多线程库(带有'-mt'),也许它可能是你的情况。
  • 现在我在ubuntu盒子上从头开始,源文件是link'this',编译命令是这个g++ -pthread mr.cpp -lboost_filesystem -lboost_system 我仍然得到同样的错误!!!
【解决方案2】:

太好了,终于成功了,这就是我所做的: 1-安装了 gcc 4.8(不确定这是否相关)。 2-下载并解压到 /usr/local 3-运行 bootstrap.sh 4-将project-config.jam中的工具集参数修改为使用gcc:4.8.1:g++-4.8; 5-运行 ./b2 --with-system 6-运行./b2 --with-filesystem 第 5 步和第 6 步均使用 root 用户完成。 7-像这样编译源文件:

# g++-4.8 mr.cpp -L /usr/local/boost_1_55_0/stage/lib -I /usr/local/boost_1_55_0 -lboost_system -lboost_filesystem -o mr

天啊,我终于要退出 Boost 了。

我认为不同的是编译器(工具集)和安装路径的一致性,特别是这两个“-L /usr/local/boost_1_55_0/stage/lib -I /usr/local/boost_1_55_0”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-02
    • 2021-06-18
    • 1970-01-01
    • 2016-06-02
    • 2018-11-03
    • 1970-01-01
    • 2012-11-08
    相关资源
    最近更新 更多