gcc编译遇到的一些问题

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






 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值