我試着寫Makefile文件在Ubuntu 14.04秩序的Makefile
這裏OpenCV的文件例如: Makefile to Compile OpenCV Code in C++ on Ubuntu/Linux
如果我嘗試喲使用它以這種形式:
CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
% : %.cpp
g++ $(CFLAGS) $(LIBS) -o [email protected] $<
我得到
make:***沒有目標。停止。
如果我嘗試
IFLAGS = `pkg-config --cflags opencv`
LFLAGS = `pkg-config --libs opencv`
all: minimal
minimal: minimal.cpp
g++ $(IFLAGS) $(LFLAGS) -o minimal minimal.cpp
我得到
g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` -o minimal minimal.cpp
/tmp/ccKWVtBh.o: In function `main':
minimal.cpp:(.text+0x4d): undefined reference to `cv::imread(std::string const&, int)'
minimal.cpp:(.text+0x123): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
minimal.cpp:(.text+0x1a6): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
minimal.cpp:(.text+0x1ce): undefined reference to `cv::waitKey(int)'
/tmp/ccKWVtBh.o: In function `cv::Mat::~Mat()':
minimal.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccKWVtBh.o: In function `cv::Mat::operator=(cv::Mat const&)':
minimal.cpp:(.text._ZN2cv3MataSERKS0_[_ZN2cv3MataSERKS0_]+0x111): undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccKWVtBh.o: In function `cv::Mat::release()':
minimal.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference to `cv::Mat::deallocate()'
/tmp/ccKWVtBh.o: In function `cv::_InputArray::_InputArray<unsigned char>(cv::Mat_<unsigned char> const&)':
minimal.cpp:(.text._ZN2cv11_InputArrayC2IhEERKNS_4Mat_IT_EE[_ZN2cv11_InputArrayC5IhEERKNS_4Mat_IT_EE]+0x17): undefined reference to `vtable for cv::_InputArray'
/tmp/ccKWVtBh.o: In function `cv::Mat_<unsigned char>::operator=(cv::Mat const&)':
minimal.cpp:(.text._ZN2cv4Mat_IhEaSERKNS_3MatE[_ZN2cv4Mat_IhEaSERKNS_3MatE]+0x77): undefined reference to `cv::Mat::reshape(int, int, int const*) const'
minimal.cpp:(.text._ZN2cv4Mat_IhEaSERKNS_3MatE[_ZN2cv4Mat_IhEaSERKNS_3MatE]+0xdd): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/tmp/ccKWVtBh.o: In function `cv::_OutputArray::_OutputArray<unsigned char>(cv::Mat_<unsigned char>&)':
minimal.cpp:(.text._ZN2cv12_OutputArrayC2IhEERNS_4Mat_IT_EE[_ZN2cv12_OutputArrayC5IhEERNS_4Mat_IT_EE]+0x2a): undefined reference to `vtable for cv::_OutputArray'
collect2: error: ld returned 1 exit status
make: *** [minimal] Error 1
但是,如果我用這種形式爲什麼標準Makefile例如沒有爲工作順利編譯
IFLAGS = `pkg-config --cflags opencv`
LFLAGS = `pkg-config --libs opencv`
all: minimal
minimal: minimal.cpp
g++ $(IFLAGS) -o minimal minimal.cpp $(LFLAGS)
我?我們應該在makefile中使用libs,include和* .cpp的順序是什麼?
你列出的第一個Makefile有沒有明確的目標,以便讓不知道,當你運行'make'建設什麼樣的。在你有'somefile.cpp'的地方運行'make somefile',它會工作。在命令行中查看庫時,會搜索*一次*。所以他們需要在*之後*使用它們的任何東西。 –