1.gcc -c test.c -o test,出错:
cannot execute binary file
带-c编译时,-o生成的是.o文件,可以使用file 命令查看文件类型。
file ./test
ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
正确做法:
gcc -o test test.c
2.遇到错误:
gcc -o test test.cpp
/tmp/cc4AjGma.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x81): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x90): undefined reference to `std::ios_base::Init::~Init()'
是因为c++的代码编译,正确做法:
g++ -o test test.cpp
3. 遇到错误:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
正确做法:
g++ -o cali calibrationProgram.cpp -std=c++11
4.遇到错误
test.cpp:(.text+0x1163): undefined reference to `cv::VideoCapture::open(int)'
test.cpp:(.text+0x116d): undefined reference to `cv::VideoCapture::isOpened() const'
test.cpp:(.text+0x11a0): undefined reference to `cv::VideoCapture::set(int, double)'
test.cpp:(.text+0x11c2): undefined reference to `cv::VideoCapture::set(int, double)'
test.cpp:(.text+0x1314): undefined reference to `cv::waitKey(int)'
/tmp/ccRcuB7e.o: In function `void cv::operator>><cv::Mat>(cv::FileNode const&, cv::Mat&)':
正确做法:编译加上cv库
g++ -o test test.cpp -std=c++11 `pkg-config --cflags --libs opencv`
5.遇到错误
test.cpp: In function ‘void chessCheck(int)’:
test.cpp:111:9: error: ‘thread’ was not declared in this scope
thread A;
需要在cpp代码中#include <thread>
6.遇到错:
/usr/bin/ld: /tmp/ccgMLGWg.o: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
正确做法:编译加上-lpthread
g++ -o test test.cpp -std=c++11 `pkg-config --cflags --libs opencv` -lpthread