gpt4 book ai didi

c++ - 链接我的项目 C++ 的问题

转载 作者:行者123 更新时间:2023-11-28 07:13:19 25 4
gpt4 key购买 nike

我必须编译并运行一个用 C++ 编写的第三方项目,不幸的是,我没有使用 C++ 的经验,在解决了所有问题之后打桩问题,我面临一系列的链接问题。我的很多类和函数都收到典型的链接错误的“未定义引用”。由于代码是真实的-非常庞大,由许多不同的文件组成,我正在向您展示以下非常小的主文件,我尝试在其中编译和运行我有问题的功能之一,我也在这里得到平衡小程序同样的链接错误。所以希望如果我设法找到解决这段代码的方法,我会与其他人一起管理。在向您展示代码本身之前,让我在广告中说-vanced,在这种情况下,我试图从 cplex.h 调用一个函数,并且为了避免一些建议,我已经正确安装了 cplex(我可以从我可以使用一些 cplec func 的事实中验证一件事-和命令没有问题)并且我还添加了 cplex 作为其中之一我的外部库(我使用 Eclipse IDE),而且我遇到了同样的 lin-非 cplex 的其他功能的国王错误。最后,我在过去几天对此进行了广泛的研究网站和一般关于链接错误而无法解决靠我自己。因此,非常感谢任何人的帮助。所以这是代码本身:

#include <iostream>
#include "/home/used/cplex/include/ilcplex/cplex.h"// that's my cplex.h path
using namespace std;
int main(){
double temp;
int a,c;
CPXENVptr env;// in these two uses of cplex variables I don't get any error
CPXNETptr net;//
CPXNETgetdj( env , net , &temp , c , a ); // when I try to use this or any function from cplex I get an linking error
return( 0 );
}

我还展示了在 cplex.h 中编写的原始函数,看看我是否这样做正确使用该函数,这样我就不会将链接器与错误使用混淆功能。

CPXLIBAPI
int CPXPUBLIC
CPXNETgetdj (CPXCENVptr env, CPXCNETptr net, double *dj, int begin,
int end);

打印机错误本身是:

Building target: structures
Invoking: Cross G++ Linker
g++ -o "structures" ./src/div.o ./src/prod.o ./src/structures.o
./src/structures.o: In function `main':
/home/used/workspace/structures/Debug/../src/structures.cpp:21: undefined reference to `CPXNETgetdj'
collect2: error: ld returned 1 exit status

最佳答案

#include "/home/used/cplex/include/ilcplex/cplex.h" 仅当 / 被搜索包含时才有效。也没有关于实际包含 CPLEX 库的论据。

我建议将其更改为 #include "ilcplex/cplex.h" 以实现可移植性,然后像这样运行它:

g++ -o "structures" ./src/div.o ./src/prod.o ./src/structures.o \
-I/home/used/cplex/include -L/home/used/cplex/lib/x86-64_debian4.0_4.1/static_pic \
-lcplex -lilocplex

尽管您必须创建库的实际路径(/home/used/cplex/lib/x86-64_debian4.0_4.1/static_pic 是否正确)并且可能是正确的它到正确的那个。

基于找到的文档 here .

关于c++ - 链接我的项目 C++ 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20634566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com