我无法编译使用MagickWand和CMake的程序。我收到此错误:
<td><span> {{ getProductName(purchase.productId) }} </span></td>
这是我的CMakeLists.txt:
[ 33%] Linking CXX executable bin/ScreenRecorder
/usr/bin/ld: CMakeFiles/ScreenRecorder.dir/source/main.cpp.o: in function `std::thread::thread<void (&)(), , void>(void (&)())':
main.cpp:(.text._ZNSt6threadC2IRFvvEJEvEEOT_DpOT0_[_ZNSt6threadC5IRFvvEJEvEEOT_DpOT0_]+0x20): undefined reference to `pthread_create'
/usr/bin/ld: CMakeFiles/ScreenRecorder.dir/source/screenshot.cpp.o: in function `printScrn(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
screenshot.cpp:(.text+0xd): undefined reference to `MagickWandGenesis'
/usr/bin/ld: screenshot.cpp:(.text+0x1a): undefined reference to `NewMagickWand'
/usr/bin/ld: screenshot.cpp:(.text+0x31): undefined reference to `MagickReadImage'
/usr/bin/ld: screenshot.cpp:(.text+0x4f): undefined reference to `MagickWriteImage'
/usr/bin/ld: screenshot.cpp:(.text+0x62): undefined reference to `DestroyMagickWand'
/usr/bin/ld: screenshot.cpp:(.text+0x6b): undefined reference to `MagickWandTerminus'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/ScreenRecorder.dir/build.make:99: bin/ScreenRecorder] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/ScreenRecorder.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
我尝试使用诸如 $ {ImageMagick_MagickWand_INCLUDE_DIR} 和 $ {ImageMagick_MagickWand_LIBS_DIR} 这样的变量,但是它表示未找到“ wand / MagickWand.h” 。 感谢您的回答。
答案 0 :(得分:0)
我能够通过将自动生成的变量括在引号中来解决类似的问题:
Python 3.7.3 (default, Mar 27 2019, 16:54:48)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from turtle import Turtle
>>> t1 = Turtle()
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.461 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.462 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.462 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.463 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.463 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.463 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.463 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.463 python[10363:4080288] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-09-11 15:26:36.472 python[10363:4080288] HIToolbox: received notification of WindowServer event port death.
2019-09-11 15:26:36.472 python[10363:4080288] port matched the WindowServer port created in BindCGSToRunLoop
[Restored Sep 11, 2019 at 3:26:48 PM]
之所以解决了这个问题,是因为变量是CMake列表。 没有引号,它们被连接成一个长字符串:
INCLUDE_DIRECTORIES(
"${ImageMagick_INCLUDE_DIRS}"
)
TARGET_LINK_LIBRARIES(MyProject
"${ImageMagick_LIBRARIES}"
)
但是,使用引号将列表中的不同元素用分号分隔:
MESSAGE(${ImageMagick_INCLUDE_DIRS})
MESSAGE(${ImageMagick_LIBRARIES})
->
1> [CMake] /usr/include/ImageMagick-6/usr/include/x86_64-linux-gnu/ImageMagick-6
1> [CMake] /usr/lib/x86_64-linux-gnu/libMagickWand-6.Q16.so