【问题标题】:Cplex library gcc compilation link errorCplex库gcc编译链接错误
【发布时间】:2015-09-01 10:54:56
【问题描述】:
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 

我正在尝试从 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): undefined reference to `CPXgetslack'
mipex1.c:(.text+0x5f9): undefined reference to `CPXwriteprob'
mipex1.c:(.text+0x64d): undefined reference to `CPXfreeprob'
mipex1.c:(.text+0x697): undefined reference to `CPXcloseCPLEX'
mipex1.c:(.text+0x6e3): undefined reference to `CPXgeterrorstring'
collect2: error: ld returned 1 exit status

【问题讨论】:

  • 好的,知道了,我的错,对不起。
  • 不,它是一个目录,里面有 libcplex.a。我制作了一张 cd,我在一个目录中
  • 顺便说一句,您是否尝试在库名称之前提供链接路径?
  • 类似.... -L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic -lcplex?

标签: c gcc compiler-errors undefined-reference cplex


【解决方案1】:

order of appearance of the library matters。将编译语句更改为

gcc -I/opt/cplex-studio-125/cplex/include mipex1.c L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic -lcplex

(通用版)

gcc -I/<path> -L<path> <source.c> -l<lib>

将库放在源文件之后,这样,链接器将在库中搜索从源文件调用的函数。

【讨论】:

  • @piedar NVM,添加了一个更好的。 :-)
猜你喜欢
  • 2014-05-30
  • 2016-02-12
  • 2019-01-30
  • 1970-01-01
  • 2015-01-06
  • 2015-11-28
  • 2019-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多