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

Problems with Linking my Project C++

本文关键字:问题 C++ 项目 我的 链接      更新时间:2023-10-16

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

#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是否为正确路径),并可能将其更正为正确路径。

基于此处的文档。