0

我已经使用 eclipse 开发了一个 C++ 项目。当我Run从 IDE 中启动命令时,一切都会正常运行,并且程序会成功退出。这是使用 Eclipse 的 make 文件获得的构建输出:

**** Build of configuration Debug for project IVPM ****

make all 
Building file: ../IVPM.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"IVPM.d" -MT"IVPM.d" -o "IVPM.o" "../IVPM.cpp"
Finished building: ../IVPM.cpp

Building file: ../TemplateMatx3.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"TemplateMatx3.d" -MT"TemplateMatx3.d" -o "TemplateMatx3.o" "../TemplateMatx3.cpp"
Finished building: ../TemplateMatx3.cpp

Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -I/usr/local/include/opencv -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: IVPM
Invoking: GCC C++ Linker
g++ -L/usr/local/lib -o "IVPM"  ./IVPM.o ./Matx3.o ./TemplateMatx3.o ./main.o   -lopencv_core -lpng -lopencv_highgui
Finished building target: IVPM

**** Build Finished ****

我现在试图自己编写一个makefile,但无法成功编译。这是我到目前为止所做的:

all:main

main:IVPM.o TemplateMatx3.o
    g++ IVPM.o TemplateMatx3.o -L/usr/local/lib -lopencv_core -lpng -lopencv_highgui -o main -c main.cpp

TemplateMatx3.o:TemplateMatx3.cpp
    g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c TemplateMatx3.cpp

IVPM.o:IVPM.cpp
    g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c IVPM.cpp

clean:
    rm -rf *o main 

但是使用命令在shell上编译make会导致以下错误:

g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c IVPM.cpp
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -I/usr/include/c++/4.5.2 -O0 -g3 -Wall -fmessage-length=0 -std=c++0x -c TemplateMatx3.cpp
g++ IVPM.o TemplateMatx3.o -L/usr/local/lib -lopencv_core -lpng -lopencv_highgui -o main -c main.cpp
In file included from /usr/include/c++/4.5/type_traits:35:0,
                 from IVPM.h:39,
                 from main.cpp:8:
/usr/include/c++/4.5/bits/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
In file included from main.cpp:9:0:
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::loadImagesFromFileAndProcessAndSave(const std::string&, const std::string&, const std::string&, IVPM<Matx3DataType>::loadImageType, IVPM<Matx3DataType>::saveImageFormat, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:140:39: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘std::vector<TemplateMatx3<Matx3DataType>*>* IVPM<Matx3DataType>::loadImagesFromFileAndProcessAndReturn(const std::string&, const std::string&, IVPM<Matx3DataType>::loadImageType, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:208:39: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::convertMatx3VectorAndProcessAndSave(std::vector<TemplateMatx3<Matx3DataType>*>*, const std::string&, IVPM<Matx3DataType>::saveImageFormat, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:555:58: error: there are no arguments to ‘to_string’ that depend on a template parameter, so a declaration of ‘to_string’ must be available
IVPM.cpp:555:58: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::loadMatx3FromFileAndProcessAndSave(const std::string&, const std::string&, IVPM<Matx3DataType>::matx3FileType, const std::string&, IVPM<Matx3DataType>::saveImageFormat, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:704:38: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘std::vector<TemplateMatx3<Matx3DataType>*>* IVPM<Matx3DataType>::loadMatx3FromFileAndProcessAndReturn(const std::string&, const std::string&, IVPM<Matx3DataType>::matx3FileType, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType)’:
IVPM.cpp:740:38: error: no matching function for call to ‘std::basic_ifstream<char>::open(const std::string&, const std::ios_base::openmode&)’
/usr/include/c++/4.5/fstream:526:7: note: candidate is: void std::basic_ifstream<_CharT, _Traits>::open(const char*, std::ios_base::openmode) [with _CharT = char, _Traits = std::char_traits<char>, std::ios_base::openmode = std::_Ios_Openmode]
IVPM.cpp: In member function ‘void IVPM<Matx3DataType>::loadVideoAndProcessAndSave(const std::string&, const std::string&, IVPM<Matx3DataType>::saveImageFormat, float, float, float, bool, IVPM<Matx3DataType>::imageOperationType, float, float, IVPM<Matx3DataType>::interpolationType) [with Matx3DataType = double, std::string = std::basic_string<char>]’:
main.cpp:84:2:   instantiated from here
IVPM.cpp:315:118: error: ‘to_string’ was not declared in this scope
make: *** [main] Error 1

显然编译器无法找到标准库的匹配函数。但是我已经在我的编译选项中包含了 std 库,那么为什么编译器会抱怨呢?正确的程序是什么?

4

0 回答 0