Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将C可执行文件链接到OpenCV时出错_Opencv_Linker - Fatal编程技术网

将C可执行文件链接到OpenCV时出错

将C可执行文件链接到OpenCV时出错,opencv,linker,Opencv,Linker,我正在使用cMake在Ubuntu13.10下编译OpenCV 我已经编译了C++程序,它们工作得很好。 现在我正试图用这个cMakeLists.txt编译一个C文件 下面是test.c文件: 按如下方式编辑您的CMakeLists.txt: cmake_minimum_required(VERSION 2.8) project(test) find_package( OpenCV REQUIRED ) add_executable( test test.c ) target_link_libr

我正在使用cMake在Ubuntu13.10下编译OpenCV

<>我已经编译了C++程序,它们工作得很好。 现在我正试图用这个cMakeLists.txt编译一个C文件

下面是test.c文件:

按如下方式编辑您的CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
project(test)
find_package( OpenCV REQUIRED )
add_executable( test test.c )
target_link_libraries( test ${OpenCV_LIBS} )
然后是$cmake。 然后是$make,最后是$test,将-lm/lib/i386 linux gnu/libm.so.6添加到链接库中

$ gcc `pkg-config --cflags opencv` -o <output> <input> `pkg-config --libs opencv` -lm /lib/i386-linux-gnu/libm.so.6

我也犯了同样的错误,它对我起作用了

你没有对CMakeLists.txt做任何修改,只是更改了项目名称,为什么这应该起作用?仍然不适用于meDid您是否正确安装了cmake和gcc?您的代码在我的机器上运行良好。默认情况下安装了gcc,我已经使用sudo apt get install cmake命令安装了cmake。当使用同一个库编译C++代码时,一切都很好。在我的机器上,代码运行得非常好。我之所以重新编写CMakeLists.txt,是因为您的是小“c”,而应该是CMakeLists.txt。这是你的代码
Linking C executable hello
/usr/bin/ld: CMakeFiles/hello.dir/src/test.c.o: undefined reference to symbol «lrint@@GLIBC_2.1»
/lib/i386-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [hello] Erreur 1
make[1]: *** [CMakeFiles/hello.dir/all] Erreur 2
make: *** [all] Erreur 2
cmake_minimum_required(VERSION 2.8)
project(test)
find_package( OpenCV REQUIRED )
add_executable( test test.c )
target_link_libraries( test ${OpenCV_LIBS} )
$ gcc `pkg-config --cflags opencv` -o <output> <input> `pkg-config --libs opencv` -lm /lib/i386-linux-gnu/libm.so.6