所以我试图让一个示例poco程序运行与cmake一起运行。来自here。
#include <Poco/String.h>
using Poco::trim;
using Poco::trimLeft;
using Poco::trimRight;
using Poco::trimRightInPlace;
#include <iostream>
int main(int argc, char** argv)
{
std::string hello(" This is a silly string. ");
std::cout << hello << std::endl;
std::string s1(trimLeft(hello));
trimRightInPlace(s1);
std::string s2(trim(hello));
std::cout << s2 << std::endl;
return 0;
}
我可以编译并运行此命令中的代码。
g++ -o silly silly.cpp -L/usr/local/lib -lPocoFoundation -I/usr/local/include/poco
但是当我尝试将cmake与这样的文件一起使用时。
cmake_minimum_required (VERSION 2.6)
project (Silly)
ADD_DEFINITIONS(
-std=c++11
)
# the version number
set (Silly_VERSION_MAJOR 0)
set (Silly_VERSION_MINOR 1)
include_directories (${PROJECT_BINARY_DIR})
include_directories ("/usr/local/include/poco")
include_directories ("/usr/local/lib")
# add the libs
set (EXTRA_LIBS ${EXTRA_LIBS} PocoFoundation)
# add the executable
add_executable (Silly silly.cpp)
target_link_libraries (Silly ${EXTRA_LIBS})
我收到此错误。
CMakeFiles/Silly.dir/silly.cpp.o: In function `Poco::Ascii::properties(int)':
silly.cpp:(.text._ZN4Poco5Ascii10propertiesEi[_ZN4Poco5Ascii10propertiesEi]+0x21): undefined reference to `Poco::Ascii::CHARACTER_PROPERTIES'
collect2: error: ld returned 1 exit status
make[2]: *** [Silly] Error 1
make[1]: *** [CMakeFiles/Silly.dir/all] Error 2
make: *** [all] Error 2
这是我的详细输出
/usr/bin/c++ -I/home/matt/projects/billy/build -I/usr/local/include/poco -I/usr/local/lib -std=c++11 -o CMakeFiles/Silly.dir/silly.cpp.o -c /home/matt/projects/billy/src/silly.cpp
Linking CXX executable Silly
/usr/bin/cmake -E cmake_link_script CMakeFiles/Silly.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/Silly.dir/silly.cpp.o -o Silly -rdynamic -lPocoFoundation
CMakeFiles/Silly.dir/silly.cpp.o: In function `Poco::Ascii::properties(int)':
silly.cpp:(.text._ZN4Poco5Ascii10propertiesEi[_ZN4Poco5Ascii10propertiesEi]+0x21): undefined reference to `Poco::Ascii::CHARACTER_PROPERTIES'
collect2: error: ld returned 1 exit status
make[2]: *** [Silly] Error 1
make[2]: Leaving directory `/home/matt/projects/billy/build'
make[1]: *** [CMakeFiles/Silly.dir/all] Error 2
make[1]: Leaving directory `/home/matt/projects/billy/build'
make: *** [all] Error 2