我正在尝试将我的JNI Android应用程序与OpenCV链接,但我收到了这些错误
./obj/local/armeabi
/libopencv_calib3d.a(calibinit.cpp.o): In function `cvDrawChessboardCorners':
calibinit.cpp:(.text+0x20a): undefined reference to `cvLine'
calibinit.cpp:(.text+0x244): undefined reference to `cvLine'
calibinit.cpp:(.text+0x26e): undefined reference to `cvCircle'
calibinit.cpp:(.text+0x2ec): undefined reference to `cvLine'
calibinit.cpp:(.text+0x4ce): undefined reference to `cvLine'
calibinit.cpp:(.text+0x504): undefined reference to `cvLine'
calibinit.cpp:(.text+0x532): undefined reference to `cvCircle'
./obj/local/armeabi/libopencv_calib3d.a(calibinit.cpp.o): In function `cvFindChessboardCorners':
calibinit.cpp:(.text+0x1b6a): undefined reference to `cvRectangle'
./obj/local/armeabi/libopencv_calib3d.a(calibinit.cpp.o): In function `cv::findCirclesGrid(cv::_InputArray const&, cv::Size_<int>, cv::_OutputArray const&, int, cv::Ptr<cv::FeatureDetector> const&)':
calibinit.cpp:(.text+0x5058): undefined reference to `cv::FeatureDetector::detect(cv::Mat const&, std::vector<cv::KeyPoint, std::allocator<cv::KeyPoint> >&, cv::Mat const&) const'
./obj/local/armeabi/libopencv_calib3d.a(circlesgrid.cpp.o): In function `cv::findCirclesGridDefault(cv::_InputArray const&, cv::Size_<int>, …Run Code Online (Sandbox Code Playgroud) 我一直在努力编译我的项目而且我遇到了undefined reference错误.例如.:
installertest.cpp:(.text+0x9d1): undefined reference to `XmlRpcValue::makeArray()'
...
installertest.cpp:(.text+0xede): undefined reference to `dbcancel'
installertest.cpp:(.text+0xefd): undefined reference to `dbfcmd'
installertest.cpp:(.text+0xf0f): undefined reference to `dbsqlexec'
installertest.cpp:(.text+0xf2d): undefined reference to `SHA1_Init'
...
Run Code Online (Sandbox Code Playgroud)
我的命令行是:
g++ -o installertest \
-lsybdb \
-lxmlrpc \
-lxmlrpc_cpp \
-lxmlrpc_xmlparse \
-lxmlrpc_xmltok \
-lxmlrpc_util \
-lxmlrpc++ \
-lxmlrpc_server_cgi \
-lssl \
-std=c++0x \
ContractData.o installertest.o
Run Code Online (Sandbox Code Playgroud)
objdump -T显示符号位于.so文件中.例如.:
libsybdb.so:
...
0000000000011c30 g DF .text 0000000000000083 Base dbcancel
...
/usr/lib/libxmlrpc_cpp.so:
...
0000000000002e78 g DF .text 0000000000000092 Base _ZN11XmlRpcValue9makeArrayEv …Run Code Online (Sandbox Code Playgroud) 我在lubuntu 12.10发行版上安装了opencv.然后,当我尝试编译使用opencv的代码时,它说它无法找到它.所以我在终端尝试:
pkg-config --cflags --libs opencv
Run Code Online (Sandbox Code Playgroud)
它回答我,它找不到opencv.但文件安装在/ usr/lib中.我不明白为什么找不到它们.
我正在构建一个依赖于静态库 A 的可执行文件,而静态库 A 又依赖于静态库 B。当我构建应用程序时,是否还需要在构建脚本中链接到 B?
更具体地说,我是否需要这样做-la -lb,或者仅与 A via 链接-la就足够了?
我目前正在构建一个相当大的应用程序,使用cmake生成跨平台构建脚本。在组合cmake构建脚本的过程中,我发现了gcc链接行排序的痛苦。
基本问题是以错误的顺序包含静态库会导致未使用的库符号被丢弃,随后的依赖库无法找到它们。
因此,我处于cmake生成可以正常编译的Visual Studio构建系统的情况,但是unix makefile会引发各种“未定义符号”错误。我已经解决了这个问题-在add_executable命令中,我两次包含了静态库。
我希望有一种更标准/更好的方式来解决此问题。由于我不是唯一的开发人员,并且大多数常规开发都是在Windows中完成的,所以我真的想要一个与链接顺序无关的CMake脚本。Windows开发人员只是不处理此链接顺序问题。最重要的是,弄清楚正确的顺序将非常困难-我没有那么容易获得的信息,并且有很多静态库(大约70个)。
在互联网上搜索后,我确实了解了-static和-dynamic标志,但是让CMake包含它们并不是显而易见的,gcc抱怨无法找到动态库。
无论如何,我欢迎有关如何做正确事情的建议。
我已经使用cmake编译了glfw3和包含的示例,并且没有问题.写我的第一个项目.作为opengl和glfw的新手,对C和cmake没有经验,我很难理解示例构建文件,甚至要在我的项目中使用哪些链接和/或编译器参数.
假设我现在只有一个文件夹和一个文件boing.c.我怎么编译它?
简单的运行gcc -lglfw3 -lm -lGL -lGLU boing.c给出了一个未定义引用的墙,从sin和atan2开始,然后是各种gl和glfw的东西.我错过了什么?
我将如何编写makefile?是否有cmake模板或样本,我只是不明白如何使用或适应?有没有人知道使用glfw3的开源项目(或更好,一个小例子或模板) - 所以我可以环顾四周?
当我想在某个时候进入多平台时,我猜cmake会是最好的.但是我如何在没有太多麻烦的情况下获得编译**的东西,所以我可以开始学习一些教程..?
我是一个使用32位Ubuntu raring的温和的菜鸟.现在就使用Vim.
我想只从静态库(即.a文件)构建一个可执行文件.这是可能的,因为该main()函数包含在其中一个库中.
该add_executable()功能要求我提供至少一个源文件.但这不是我想要做的.
我正在尝试编译一段使用 libusb 的代码:
#include <stdio.h>
#include <libusb-1.0/libusb.h>
#include <assert.h>
int main(void) {
libusb_context *context = NULL;
int rc = 0;
rc = libusb_init(&context);
assert(rc == 0);
libusb_exit(context);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译后gcc -lusb -lusb-1.0 sample.c -o sample出现以下错误:
/tmp/ccr65JBT.o: In function `main':
sample.c:(.text+0x2e): undefined reference to `libusb_init'
sample.c:(.text+0x62): undefined reference to `libusb_exit'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
为了确保 libusb 在我的系统上可用:
raven@enforcer:~/sample$ pkg-config --libs libusb-1.0
-lusb-1.0
raven@enforcer:~/sample$ pkg-config --libs libusb
-lusb
Run Code Online (Sandbox Code Playgroud)
我正在运行带有 gcc 7.3.0-16ubuntu3 的 Ubuntu 18.04,如何修复?
在 ubuntu 20.04 上,当我使用 clang-8 或 clang-9(clang 版本 9.0.1-12)编译包含对 libm 的引用的简单代码时,它将失败并显示错误“未定义的引用__pow_finite”
#include <math.h>
int main()
{
double x=1, y=1;
x = pow(x,y);
}
Run Code Online (Sandbox Code Playgroud)
clang-9 -lm test.c -ffast-math
/usr/bin/ld: /tmp/test-9b1a45.o: in function `main':
test.c:(.text+0x2a): undefined reference to `__pow_finite'
readelf -Ws /lib/x86_64-linux-gnu/libm.so.6| grep pow_finite
626: 000000000002ed90 65 IFUNC GLOBAL DEFAULT 17 __pow_finite@GLIBC_2.15
Run Code Online (Sandbox Code Playgroud)
gcc 没问题。知道这里有什么问题吗?
C++ 也有同样的问题:
#include <cmath>
int main()
{
double x=1, y=1;
x = pow(x,y);
}
Run Code Online (Sandbox Code Playgroud)
编辑
我实际上使用了-lm,我只是忘记放入文本。如果我不添加它,则是另一个错误。
$ clang-9 test.c
/usr/bin/ld: /tmp/test-3389a6.o: in function `main':
test.c:(.text+0x25): undefined …Run Code Online (Sandbox Code Playgroud) 最近,我试图构建一个应用程序,它使用一些库,以共享对象文件的形式提供.我在编写CPP代码时浪费了很多时间,但它没有用.
下面是命令,以前我试图编译代码 -
g++ -I/opt/ros/indigo/include/ -I/usr/include/eigen3/ -L/opt/ros/indigo/lib/ -lorocos-kdl -lkdl_parser test.cpp -o test
Run Code Online (Sandbox Code Playgroud)
以上命令始终显示许多undefined references错误.只是为了好奇,我改变了参数的顺序.以下是命令,它正在工作 -
g++ -L/opt/ros/indigo/lib -I/opt/ros/indigo/include -I/usr/include/eigen3 test.cpp -lorocos-kdl -lkdl_parser -o test
Run Code Online (Sandbox Code Playgroud)
我在这里发布了完整的代码和解决方案.
我的问题是为什么将参数传递给g ++的顺序很重要?有没有其他方法可以避免将来出现这类问题?
c++ ×6
c ×5
cmake ×3
g++ ×2
linker ×2
linux ×2
opencv ×2
android ×1
android-ndk ×1
clang ×1
clang++ ×1
gcc ×1
glfw ×1
ld ×1
libusb ×1
libusb-1.0 ×1
pkg-config ×1
ubuntu-20.04 ×1