【问题标题】:Using a third party library (sbpl)使用第三方库 (sbpl)
【发布时间】:2015-03-03 17:40:25
【问题描述】:

我在 linux\ubuntu 上构建并安装了一个名为 sbpl 的库。安装后我有以下文件:

usr/local/include/sbpl(这里有一堆文件,包括一个headers.h 文件)

usr/local/lib 有一个libsbpl.so 文件

现在我在编译一个简单的程序时遇到了一些麻烦:

yus.cpp

#include <iostream>
#include <sbpl/headers.h> 

int main()
{
  EnvironmentType type;
  return 0;
}

使用这些命令编译我得到错误:

$ g++ yus.cpp -Iusr/local/include/sbpl   gives the following error 
"error: 'EnvironmentType' was not declared in this scope"

$ g++ yus.cpp -L.-lsbpl   gives the same error as above

如何正确编译和链接库?

【问题讨论】:

  • 试试g++ yus.cpp -I/usr/local/include -L/usr/local/lib -lsbpl
  • 仍然给我同样的错误:(
  • /usr/local/include/ 还是usr/local/include?如果是usr/local/include 试试g++ yus.cpp -Iusr/local/include -Lusr/local/lib -lsbpl
  • 标题中是否定义了EnviromentType?我不太相信这个测试文件中的一次:github.com/sbpl/sbpl/blob/master/src/test/main.cppEnviromentType在主文件中定义

标签: c++ linux shared-libraries


【解决方案1】:

enum EnvironmentType的定义从main.cpp移动到headers.h,然后运行g++ yus.cpp -I/usr/local/include -L/usr/local/lib -lsbpl

【讨论】:

    猜你喜欢
    • 2017-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多