0

我有一个主项目和一个图书馆项目。当我尝试在 Eclipse 中构建时,我不断收到此错误:

make all 
Building file: ../src/hello/Hello.cpp
Invoking: GCC C++ Compiler
g++ -I"/Users/pdl/Development/HelloWorld/Namer/src/namer" 
-include"/Users/pdl/Development/HelloWorld/Namer/src/namer/World.h" -O0 -g3 -Wall -c 
-fmessage-length=0 -MMD -MP -MF"src/hello/Hello.d" -MT"src/hello/Hello.d" -o "src/hello/Hello.o" "../src/hello/Hello.cpp"
Finished building: ../src/hello/Hello.cpp

Building target: Hello
Invoking: MacOS X C++ Linker
g++ -L"/Users/pdl/Development/HelloWorld/Namer" -o "Hello"  ./src/hello/Hello.o 
-l"/Users/pdl/Development/HelloWorld/Namer/src/namer/World.h"
ld: library not found for -l/Users/pdl/Development/HelloWorld/Namer/src/namer/World.h
collect2: ld returned 1 exit status
make: *** [Hello] Error 1

我不是在尝试调试。我只是在尝试构建。

先感谢您。


这是我的代码:

你好是我的主要项目,Namer 是我的图书馆。

在我的 Hello 项目中,我有一个这样的文件夹结构: src -> hello

你好.cpp:

#include <stdio.h>
#include "World.h"

int main() {
  printf("Hello %s\n", getWorld().c_str());
  return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.6)
project(Hello)
find_package(Namer REQUIRED)
include_directories("${Namer_INCLUDE-DIRS}")
add_executable(hello main.cpp)
target_link_libraries(hello ${Namer_LIBRARIES})

FindNamer.cmake

find_path(Namer_INCLUDE_DIRS World.h /usr/include "$ENV{NAMER_ROOT}")

find_library(Namer_LIBRARIES namer /usr/lib "$ENV{NAMER_ROOT}")

set(Namer_FOUND TRUE)

if (NOT Namer_INCLUDE_DIRS)
    set(Namer_FOUND FALSE)
endif (NOT Namer_INCLUDE_DIRS)

if (NOT Namer_LIBRARIES)
    set(Namer_FOUND FALSE)
endif (NOT Namer_LIBRARIES)

在我的 Namer 项目中,我有一个这样的文件夹结构: src -> namer

世界.cpp:

#include "World.h"

std::string getWorld() { return "Earth"; }

int main() {
  printf("We are in Namer %s\n", getWorld().c_str());
  return 0;
}

世界.h:

#include <string>

std::string getWorld();

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.6)
project(Namer)
include_directories("${CMAKE_SOURCE_DIR}")
add_library(namer World.cpp World.h)
4

1 回答 1

0

看来您正在构建“src/hello/Hello.o”但搜索错误。-l"/Users/pdl/Development/HelloWorld/Namer/src/namer/World.h"应该是库而不是链接器命令中的标头。检查您的项目设置。

于 2013-09-09T23:25:05.670 回答