在Linux上运行C ++可执行文件

时间:2016-02-08 17:15:24

标签: c++ opencv c++11 g++

我正在尝试使用OpenCV在Linux中编译执行C ++程序。

当我输入

    SELECT r.progid
         , r.batch
      FROM student s
      JOIN registers r
        ON r.studentid = s.studentid 
      JOIN offers o
        ON o.courseno = r.courseno
      JOIN instructor i
        ON i.instructorid = o.instructorid  
     WHERE i.instructorname = 'P M Jaat' 
       AND o.acadyear BETWEEN '2007-01-01' AND '2011-12-31';

正确生成g++ -c facedetection.cpp -std=c++11 -o facedetection 文件。请注意,我使用facedetection因为我有错误建议这样做。

执行-std=c++11后,我尝试使用chmod o+x facedetection执行它,但是我收到错误:

./facedetection

有什么问题?

1 个答案:

答案 0 :(得分:10)

使用-c进行编译时,它会生成一个对象(.o)文件,而不是可执行文件。您需要在没有-c的情况下编译它以生成可执行文件。

较大的C ++程序将有多个.cpp文件;对于每个.cpp文件,您将使用-c进行编译以生成各自的.o文件。然后,您将链接这些.o文件(运行g++而不-c)以生成最终的可执行文件。

相关问题