make文件编译错误

时间:2013-03-07 00:03:22

标签: c++ eclipse makefile g++

我使用eclipse开发了一个C ++项目。当我从IDE中启动Run命令时,一切都会正常工作,程序会成功退出。 这是使用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 

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

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库的匹配函数。但是我在编译选项中包含了std库,为什么编译器会抱怨?什么是正确的程序?

0 个答案:

没有答案