C ++ Eclipse ld:找不到-l的库

时间:2013-09-09 23:13:14

标签: c++ eclipse g++ libraries

我有一个主项目和一个图书馆项目。当我尝试在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

我不是想调试。我只是想建立。

提前谢谢你。


这是我的代码:

Hello是我的主项目,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 - &gt;命名器

World.cpp:

#include "World.h"

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

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

World.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)

1 个答案:

答案 0 :(得分:0)

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