English 中文(简体)
奇异 Linker 错误
原标题:Weird Linker Error
#include path
include_directories(
${PROJECT_SOURCE_DIR}/include
${HGE_INCLUDE_DIR}
${IKL_INCLUDE_DIR}
${BOOST_DIRECTORY}
)

#include all files
FILE(GLOB CORE_SRCS source/core/*.cpp)
FILE(GLOB TOOL_SRCS source/tools/*.cpp)
FILE(GLOB GAME_SRCS source/game/*.cpp)

#Making a compiled library
add_library(GAMECORE_LIBRARY ${CORE_SRCS} ${HGE_LIBRARY} ${HGE_HELPER_LIBRARY})

#add executable
add_executable(DemoGame ${GAME_SRCS})

##link executable to HGE lib
TARGET_LINK_LIBRARIES(DemoGame ${HGE_LIBRARY} ${HGE_HELPER_LIBRARY} ${IKL_LIBRARY} GAMECORE_LIBRARY)

if(BUILD_TOOLS)
add_executable(EntityTool ${TOOL_SRCS})
TARGET_LINK_LIBRARIES(EntityTool ${HGE_LIBRARY} ${HGE_HELPER_LIBRARY} ${IKL_LIBRARY} GAMECORE_LIBRARY)
endif(BUILD_TOOLS)

这是我现在的花言巧语...

I get a weird linker error for hgeGUI class
eg : DemoGame/source/core/GameMainMenu.cpp:74: undefined reference to `hgeGUI::hgeGUI()

This only happens when I try to compile the core files into a static library. When I add the executable with the CORE_SRCS and remove the dependencies on my current compiled library .. it will work fine..

我还尝试将 hgegui.cpp 文件复制到我的核心源目录... 并更改 改为

之后我的链接密码解决了问题, 但我得到分割断层断层, 但我猜连接前一步的文件是不对的 。

Here s a link to their .h file
http://trac.assembla.com/snowscape/browser/hge/include/hgegui.h

最佳回答

看起来你再次滥用了 ${HGE_Libriary}}/code>和${HGE_HELPER_Libriary}}/code>变量。

add_library 呼叫中,您包含构成该库的所有源文件。

target_link_library 呼叫中,指定连接目标时使用的图书馆或旗帜。

因此,如果 ${HGE_LIBRARY}}/code>和 ${HGE_HELPER_LIBRARY}}{/code>指定图书馆路径为 GAMECORE_LIBRARY 的依附关系,您需要做到:

add_library(GAMECORE_LIBRARY ${CORE_SRCS})
target_link_libraries(GAMECORE_LIBRARY ${HGE_LIBRARY} ${HGE_HELPER_LIBRARY})

依赖性是过渡性的,这意味着当您指定 GAMECORE_LIBRIARY DemoGame EntityTool 的依赖性时,CMake会承认 ${HGE_LIBRARY}}/code>和 ${HGE_HELPER_LIBRAY}{/code>也是依赖性,因此您可以将其从 goal_link_librarys 调来调 DemoGame EntityTool


For further info on add_library and target_link_libraries, run:

cmake --help-command add_library
cmake --help-command target_link_libraries
问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?