|
楼主 |
发表于 2021-5-2 15:20:33
|
显示全部楼层
大概知道了,应该是要添加外部动态链接库so,如果在终端里使用g++ my.cpp -I /usr/local/include/ -o my -L /usr/local/lib/ -lOpenThreads -losgDB -losgText -losgUtil -losg -losgViewer -losgGA -losgManipulator -losgVolume -losgSim的话可以成功编译,但是不知道为啥我在VS CODE里面把tasks.json改成下面这个样子还是undefined reference
- {
- "tasks": [
- {
- "type": "cppbuild",
- "label": "C/C++: g++ 生成活动文件",
- "command": "/usr/bin/g++",
- "args": [
- "-g",
- "${file}",
- "-I/usr/local/include/",
- "-o",
- "${fileDirname}/${fileBasenameNoExtension}",
- "-L/usr/local/lib/",
- "-lOpenThreads",
- "-losgDB",
- "-losgText",
- "-losgUtil",
- "-losg",
- "-losgViewer",
- "-losgGA",
- "-losgManipulator",
- "-losgVolume",
- "-losgSim",
- ],
- "options": {
- "cwd": "${workspaceFolder}"
- },
- "problemMatcher": [
- "$gcc"
- ],
- "group": {
- "kind": "build",
- "isDefault": true
- },
- "detail": "调试器生成的任务。"
- }
- ],
- "version": "2.0.0"
- }
复制代码
X555LB:~/Documents/Code_WorkSpace/Test$ cd "/home/liukai/Documents/Code_WorkSpace/Test/" && g++ my.cpp -o my && "/home/liukai/Documents/Code_WorkSpace/Test/"my
/usr/bin/ld: /tmp/ccY0FVyZ.o: in function `main':
my.cpp.text+0x2a): undefined reference to `osgViewer::Viewer::Viewer()'
/usr/bin/ld: my.cpp:(.text+0x7a): undefined reference to `osgViewer::Viewer::setSceneData(osg::Node*)'
/usr/bin/ld: my.cpp:(.text+0xa7): undefined reference to `osgViewer::Viewer::run()'
/usr/bin/ld: my.cpp:(.text+0xb9): undefined reference to `osgViewer::Viewer::~Viewer()'
/usr/bin/ld: my.cpp:(.text+0x112): undefined reference to `osgViewer::Viewer::~Viewer()'
/usr/bin/ld: /tmp/ccY0FVyZ.o: in function `osgDB::readNodeFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
my.cpp:(.text._ZN5osgDB12readNodeFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN5osgDB12readNodeFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x16): undefined reference to `osgDB::Registry::instance(bool)'
/usr/bin/ld: my.cpp:(.text._ZN5osgDB12readNodeFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN5osgDB12readNodeFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x30): undefined reference to `osgDB::readNodeFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, osgDB::Options const*)'
collect2: error: ld returned 1 exit status
|
|