相关疑难解决方法(0)

boost.asio链接和库

我是boost.asio编程的新手,我很难连接boost库.

我的问题是,当我包含asio标头时,如何找出应该链接到我的项目的库.

例如我使用#include <boost/date_time/posix_time/posix_time.hpp>#include <boost/asio.hpp指令.

所以这是我编译它的命令:

g++ -I /usr/local/boost_1_55_0 ASIO.cpp -o HELLO -L /usr/local/lib/ -l boost_system

考虑我的boost库安装在/ usr/local/boost_1_55_0上,二进制文件在/ usr/local/lib上.

我的问题实际上是我需要在-l之后编写的

谢谢你的回答.

c++ linker g++ boost-asio

2
推荐指数
1
解决办法
5729
查看次数

即使包含库等,也未定义对 PQfinish 的引用

我正在尝试使用 libpq 编译 C++ 应用程序。在我的 Debian 上,使用以下命令可以正常编译:

g++ -I /usr/include/postgresql/ -L /usr/lib/postgresql/9.3/lib/ -lpq -o test test.cpp
Run Code Online (Sandbox Code Playgroud)

在我的 Ubuntu 上,我收到以下错误:

undefined reference to 'PQfinish'
Run Code Online (Sandbox Code Playgroud)

我已经包含了 postgresql 标头和库的链接并使用了 -lpq。我缺少什么?

c++ postgresql g++ libpq

2
推荐指数
1
解决办法
1871
查看次数

Poco无法发送电子邮件

我正在尝试使用 Poco 库发送电子邮件。平台是OS XYosemite 10.10.2我使用的是Qt 5.3 32 位我按照这里的官方说明进行操作,由于我使用的是 32 位 Qt,并且希望库静态链接,所以我使用

./configure --omit=Data/ODBC,Data/MySQL --config=Darwin32

(我不需要MySQL/ODBC模块)。它安装/usr/local正确,随后我链接了必要的动态库(PocoNet以及PocoFoundation其他 10 个库),并尝试了以下代码,我在此处找到了它。我想做的是从我的帐户本身向我的 Gmail 帐户发送一封电子邮件:

#include "MailSender.hpp"

#include <Poco/Net/MailMessage.h>
#include <Poco/Net/MailRecipient.h>
#include <Poco/Net/SMTPClientSession.h>
#include <Poco/Net/NetException.h>
#include <Poco/Net/SecureSMTPClientSession.h>
#include <Poco/Net/InvalidCertificateHandler.h>
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/Net/SSLManager.h>
#include <Poco/Net/SecureStreamSocket.h>
#include <Poco/Net/MailRecipient.h>

#include <iostream>
#include <QDebug>

using Poco::Net::InvalidCertificateHandler;
using Poco::Net::AcceptCertificateHandler;
using Poco::Net::Context;
using Poco::Net::SSLManager;
using Poco::Net::SecureStreamSocket;
using Poco::Net::SocketAddress;
using Poco::Net::SecureSMTPClientSession;
using …
Run Code Online (Sandbox Code Playgroud)

c++ qt smtp poco-libraries osx-yosemite

2
推荐指数
1
解决办法
3056
查看次数

gcc ld:确定静态库链接顺序的方法

我的可执行文件与许多静态库链接,在Linux上通常有50至100个存档。有时,这些档案中存在依赖性周期。这些库在链接命令行上出现的顺序很重要,请参见此处。尝试手动订购许多库至少要耗费大量时间,尤其是在存在循环的情况下。

问题:是否有实用程序或技术可以分析代码库并产生正确的链接命令行顺序?

c++ gcc ld static-linking

2
推荐指数
1
解决办法
1327
查看次数

如何修改Makefile以支持交叉编译?

我有以下Makefile:

CC=g++

top_srcdir=$(SRC_DIR)/cpp/src/

INCLUDES:= -I $(top_srcdir) -I $(top_srcdir)command_classes -I $(top_srcdir)platform -I $(top_srcdir)value_classes
LIBS:= -lopenzwave -lpthread -ludev
LDFLAGS += -L$(SRC_DIR) -Wl,-R$(SRC_DIR) '-Wl,-R$$ORIGIN'

all:    ozw

ozw: Main.cpp
    $(CC) $(INCLUDES) -c Main.cpp -o ozw-power-on-off.o
    $(CC) $(LIBS) $(LDFLAGS) ozw-power-on-off.o -o ozw-power-on-off.out

clean:
    rm -rf *.o *.out
Run Code Online (Sandbox Code Playgroud)

我用以下命令执行它:

  make ARCH=$TARGET_ARCH \
       CROSS_COMPILE=$TARGET_PREFIX \
       SRC_DIR=$ROOT/$PKG_BUILD
Run Code Online (Sandbox Code Playgroud)

但它忽视ARCHCROSS_COMPILE重视.我试图取代$(CC)$(MAKE)和补充-$(MAKEFLAGS),但它说Nothing to be done for 'Main.cpp'.

如何修复它并添加交叉编译支持?

c++ makefile cross-compiling

2
推荐指数
2
解决办法
7168
查看次数

当使用-static时,如何让gcc/ld遍历许多'-l library'?

我想静态编译pdf2svg所以我将能够在稳定的Debian中使用最新版本.在./configure不给--enable-static选项,所以我在手动添加Makefile -static选项链接.

不幸的是,结果并不像我怀疑的那样.链接给了我很多undefined reference错误.经过一些谷歌搜索,我发现问题是由错误的顺序引起的-lsome_lib.Gcc链接器尝试在每个库中静态链接一次,当它第一次看到它时 - 信息和Stackoverflow问题:为什么链接库的顺序有时会导致GCC错误?.

是否有可能使链接器通过库列表进行多次传递?

c++ linker gcc ld static-linking

1
推荐指数
1
解决办法
1386
查看次数

未定义C中电源功能的参考错误

可能重复:
在C中使用pow()的问题
未定义的对pow&#39; andfloor的引用'

我正在使用gcc 4.6.1.

代码段:

int main(void)
{

 int x= 2;
 int y = pow(3,x);
 printf("%d\n",y);

 return 0;
}
Run Code Online (Sandbox Code Playgroud)

终奌站:

avinash@titanic:~/Desktop/DSF$ gcc power.c -o power
/tmp/ccTJ7vAH.o: In function `main':

power.c:(.text+0x25): undefined reference to `pow'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

如果我将x替换为2,那么它将以预期的方式执行.pow函数不接受变量作为参数吗?

注意:我在源文件中包含了stdio.h和math.h.

c gcc pow

1
推荐指数
1
解决办法
2万
查看次数

Linux gcc 链接问题

我有两个名为 ( lib1 和 lib2) 的库,它们都不相互依赖。我无法控制这些库的构建方式。当我尝试链接它们时,链接顺序决定了最终可执行文件中的不同行为,

例如:

如果我将它们链接为 [1]

gcc $(CC_FLAGS) -o app.out -llib1 -llib2 
Run Code Online (Sandbox Code Playgroud)

一切正常

但是,如果我将它们链接如下 [2]

gcc $(CC_FLAGS) -o app.out -llib2 -llib1 
Run Code Online (Sandbox Code Playgroud)

在可执行文件运行期间发生分段错误。

有关此问题原因的任何建议或指示都会有所帮助。

更新:

这两个库都依赖于另一个动态库,即 Apache Thrift(版本 0.11.0),如果编译上述 [1] 选项,则在 lib1 上发生段错误,如果使用上述选项 [2] 编译,则在 lib2 上发生异常.

更新 2

该问题是由于库之间的全局命名空间冲突造成的。由于 thrift 使用 IDL 机制来生成源文件,两个库(不知何故)为其 IDL 定义定义了相同的命名空间,因此观察到了这种行为。接受以下答案为正确答案,因为它间接解决了问题。

谢谢你。

c c++

1
推荐指数
1
解决办法
122
查看次数

opencv2.4.0程序用代码g ++运行`pkg-config --cflags --libs opencv` facedetect.cpp -o opencv

我是OpenCV的新手,我已经在Ubuntu上安装了它.当我尝试运行存储在opencv-2.4.0/samples/c我的示例程序facedetect.cpp时,我无法使其工作.

我尝试通过以下命令运行它:

g++ \`pkg-config --cflags --libs opencv\` facedetect.cpp -o opencv
Run Code Online (Sandbox Code Playgroud)

但遇到以下错误:

/tmp/ccKQ8N39.o: In function `main':
facedetect.cpp:(.text+0x1b9): undefined reference to `cv::CascadeClassifier::CascadeClassifier()'
facedetect.cpp:(.text+0x1c7): undefined reference to `cv::CascadeClassifier::CascadeClassifier()'
facedetect.cpp:(.text+0x3ac): undefined reference to `cv::CascadeClassifier::load(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
facedetect.cpp:(.text+0x589): undefined reference to `cv::CascadeClassifier::load(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
facedetect.cpp:(.text+0x674): undefined reference to `cvCreateCameraCapture'
facedetect.cpp:(.text+0x744): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
facedetect.cpp:(.text+0x799): undefined reference to `cvCreateFileCapture'
facedetect.cpp:(.text+0x824): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
facedetect.cpp:(.text+0x8b3): undefined reference to `cvNamedWindow' …
Run Code Online (Sandbox Code Playgroud)

opencv

0
推荐指数
1
解决办法
1525
查看次数

Cplex 库 gcc 编译链接错误

gcc -I/opt/cplex-studio-125/cplex/include -lcplex -L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic mipex1.c 
Run Code Online (Sandbox Code Playgroud)

我正在尝试从 cplex 编译一个示例。-I选项很好。该-L选项似乎已损坏,因为它找不到函数名称。

错误在哪里?在特定链接中有一个libcplex.a.

/tmp/ccf5sKky.o: In function `main':
mipex1.c:(.text+0x9f): undefined reference to `CPXopenCPLEX'
mipex1.c:(.text+0xee): undefined reference to `CPXgeterrorstring'
mipex1.c:(.text+0x125): undefined reference to `CPXsetintparam'
mipex1.c:(.text+0x222): undefined reference to `CPXcreateprob'
mipex1.c:(.text+0x2e1): undefined reference to `CPXcopylp'
mipex1.c:(.text+0x334): undefined reference to `CPXcopyctype'
mipex1.c:(.text+0x380): undefined reference to `CPXmipopt'
mipex1.c:(.text+0x3cc): undefined reference to `CPXgetstat'
mipex1.c:(.text+0x403): undefined reference to `CPXgetobjval'
mipex1.c:(.text+0x474): undefined reference to `CPXgetnumrows'
mipex1.c:(.text+0x490): undefined reference to `CPXgetnumcols'
mipex1.c:(.text+0x4be): undefined reference to `CPXgetx'
mipex1.c:(.text+0x51c): …
Run Code Online (Sandbox Code Playgroud)

c gcc compiler-errors undefined-reference cplex

0
推荐指数
1
解决办法
1286
查看次数

如何纠正编译 OpenCV 时的“未定义引用”错误?

我已经从OpenCV官方网站下载了 C++ 中的 Eigenfaces 算法,并使用以下命令对其进行了编译:

g++ `pkg-config --cflags --libs opencv` facerec_eigenfaces.cpp -o opencv
Run Code Online (Sandbox Code Playgroud)

但我收到这些错误:

/tmp/cc0CsJ0b.o: In function `norm_0_255(cv::_InputArray const&)':
facerec_eigenfaces.cpp:(.text+0x51): undefined reference to `cv::noArray()'
facerec_eigenfaces.cpp:(.text+0x65): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facerec_eigenfaces.cpp:(.text+0x9b): undefined reference to `cv::normalize(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, int, cv::_InputArray const&)'
facerec_eigenfaces.cpp:(.text+0xa2): undefined reference to `cv::noArray()'
facerec_eigenfaces.cpp:(.text+0xb6): undefined reference to `cv::_OutputArray::_OutputArray(cv::Mat&)'
facerec_eigenfaces.cpp:(.text+0xec): undefined reference to `cv::normalize(cv::_InputArray const&, cv::_OutputArray const&, double, double, int, int, cv::_InputArray const&)'
Run Code Online (Sandbox Code Playgroud)

我不会在这里复制所有主题,但它们都是“未定义的参考”,并且我的 OpenCV 版本与我提到的链接相同。

(pkg-config --cflags --libs opencv) 的输出:

-I/usr/local/include/opencv -I/usr/local/include  /usr/local/lib/libopencv_calib3d.so …
Run Code Online (Sandbox Code Playgroud)

c++ opencv

0
推荐指数
1
解决办法
5492
查看次数

使用 openssl 编译代码时出现错误未定义对“SSL_new”的引用

我正在编写一个使用 TLSv1.2 连接服务器的 ssl 客户端代码,但总是出现找不到 openssl API 的错误,搜索互联网但没有找到太多与我的情况类似的信息。

我的代码如下:

#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <malloc.h>
#include <string.h>
#include <sys/socket.h>
#include <resolv.h>
#include <netdb.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#define FAIL    -1

SSL_CTX* init_ssl_ctx();
static int verify_cb(int ok, X509_STORE_CTX *store);

int main()
{
    int sockfd;
    struct sockaddr_in servaddr;
    int ret;
    struct sockaddr sockaddr;
    int port = 8443;
    //string ns_addr = "55.0.0.5";

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(8443);
    inet_pton(AF_INET, "55.0.0.5", &servaddr.sin_addr); …
Run Code Online (Sandbox Code Playgroud)

c++ linux openssl

0
推荐指数
1
解决办法
8504
查看次数