【问题标题】:UnitTest++ and g++ - Relative path to the libraryUnitTest++ 和 g++ - 库的相对路径
【发布时间】:2013-01-27 22:33:34
【问题描述】:

我正在尝试让 UnitTest++ 在此目录树之后的项目中工作:

Project/
|-- src/
|-- test/
|   |-- test.cpp
|-- unittest-cpp/
|   |-- UnitTest++/
|       |-- libUnitTest++.a
|       |-- src/
|            |-- UnitTest++.h
|-- Makefile

我正在项目目录中尝试使用 g++ 进行编译。我的 test.cpp 文件包含 UnitTest++ 入门代码。

我尝试了以下方法:

g++ -Lunittest-cpp/UnitTest++/ -lUnitTest++ -Iunittest-cpp/UnitTest++/src/ \
test/test.cpp -o Test

如果我理解得很好,-L 是给出静态库的路径。 -l(小 L)用于库名,-I(大写 i)用于包含路径。

我得到两个不同的结果。它要么告诉我它在 /usr/bin/ 中找不到该库???或者它告诉我有未定义的对 unittest::* 的引用。

是因为我提供了无法编译的库的相对路径吗?我是通过多个目录使用 g++ 的新手,我试图在让它在我的 Makefile 中工作之前了解它是如何工作的。

[编辑]:在链接库和头文件之前必须给出 test/test.cpp 参数。所以,这行得通:

g++ test/test.cpp -Lunittest-cpp/UnitTest++ -lUnitTest++ -Iunittest-cpp/UnitTest++/src -o Test

【问题讨论】:

    标签: g++ unittest++


    【解决方案1】:

    编译时必须在其依赖项之前给出要编译的文件(在此上下文中为 test.cpp)。这有效:

    g++ test/test.cpp -Lunittest-cpp/UnitTest++ -lUnitTest++ -Iunittest-cpp/UnitTest++/src -o Test
    

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 2014-06-05
      • 2015-04-24
      • 2010-09-15
      • 1970-01-01
      • 2013-07-14
      • 2010-12-17
      • 1970-01-01
      • 2014-02-06
      相关资源
      最近更新 更多