#c #cmake #poco
#c #cmake #poco
Вопрос:
Итак, я пытаюсь запустить пример программы poco, работающей с cmake. Отсюда.
#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
Комментарии:
1.
I can compile and run the code from this command
что, если вы попробуете точную строку из вывода cmake:/usr/bin/c -I/usr/local/include/poco -I/usr/local/lib -std=c 11 -c silly.cpp -o silly -lPocoFoundation
?2. Попробуйте использовать
link_directories("/usr/local/lib")
вместоinclude_directories("/usr/local/lib")