cmake过程正常完成,接下来的make过程出现报错:
查看报错提示,usehello.cpp代码中用到的printhello()函数,实际为另外的动态链接库(有对应源文件中的printhello()定义和头文件中printhello()的声明,生成的库文件名为hello_shared,对应.so文件为libhello_shared.so)中定义的函数。
make报错的原因是代码中用到的库文件未在cmakelist.txt中链接到库文件。
在cmakelists中为代码生成可执行文件后加上一句链接到所要用的库文件的命令即可。链接到库文件的指令:target_link_libraries(useHello hello_shared)。其中,usehello为待执行的源文件,hello_shared为库文件名称。