GCC在链接程序时,报"undefined reference to .."错误

umbrook umbrook 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在Common.h下
有2个函数为
SWORDFISH_DLL_SPEC time_t SwordFishTime();
SWORDFISH_DLL_SPEC uint32 SwordFishMilliTime();

SWORDFISH_DLL_SPEC的定义在另外一个.h文件
#if PLATFORM == PLATFORM_WINDOWS
# define SWORDFISH_DLL_SPEC __declspec(dllexport)
# ifndef DECLSPEC_NORETURN
# define DECLSPEC_NORETURN __declspec(noreturn)
# endif //DECLSPEC_NORETURN
#else //PLATFORM != PLATFORM_WINDOWS
# define SWORDFISH_DLL_SPEC
# define DECLSPEC_NORETURN
#endif //PLATFORM

swordFishTime和SwordFishMilliTime的实体函数在一个CPP文件中。

inline time_t SwordFishTime()
{
return sWorld.GetGameTime();//sWorld为单键模式的一个实体
}

inline uint32 SwordFishMilliTime()
{
return sWorld.GetMillGameTime();
}


这两个函数在很多地方被调用。一共13个项目,在G++下都编译通过。但是在链接可执行文件时,
编译器报错:undefine reference


obj/Debug/src/swordfishd/WorldRunnable.o: In function `WorldRunnable::run()':
undefined reference to `SwordFishMilliTime()'
undefined reference to `SwordFishMilliTime()'
/usr/local/mmo/Server/trunk/src/swordfishd/WorldRunnable.cpp:93: undefined reference to `SwordFishMilliTime()'
obj/Debug/src/swordfishd/WorldRunnable.o:/usr/local/mmo/Server/trunk/src/swordfishd/WorldRunnable.cpp:100: more undefined references to `SwordFishMilliTime()' follow


请问是为什么啊?如何让其链接成功呢?
...全文

相关推荐

undefined reference to 'pthread_create'的解决方法

undefined reference to 'pthread_create'的解决方法,需要的朋友可以参考一下

weixin_38523728

【GCC编译优化系列】GCC链接失败的错误提示 undefined reference to ‘xxx‘ 可能还有一种情况你没注意到?

GCC在编译-链接过程中,很常见的一种链接错误就是 **undefined reference to 'xxx'**,可能你对这种错误的解决方式已经了然于胸了,但本文要介绍的一种情况,可能你未曾注意到,如果按照往常的解决思路并不一定能帮助你解决问题。带着这个问题,本文将给大家剖开一个新的知识点,希望对大家今后排查此类问题有所帮助。.........

架构师李肯

undefined reference to ‘pthread_create’的解决方法

照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误: undefined reference to ‘pthread_create’undefined reference to ‘pthread_join’ 问题原因:    pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。 问题解决:    在编译中要加 -lpthread参数    gcc thread.c -o thread -lpthr

weixin_38698860

freetype-2.4.6.tar.bz2 undefined reference to `FT_Library_SetLcdFilter'

/opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so:-1: 错误:undefined reference to `FT_Library_SetLcdFilter'

zfuwen

GCC命令详解

GCC 命令行详解 1。gcc包含的c/c++编译器 gcc,cc,c++,g++,gcc和cc是一样的,c++和g++是一样的,一般c程序就用gcc编译,c++程序就用g++编译 2。gcc的基本用法 gcc test.c这样将编译出一个名为a.out的程序 gcc test.c -o test这样将编译出一个名为test的程序,-o参数用来指定生成程序的名字

xxp1002
评论 12
收藏 已收藏
分享
返回顶部
umbrook
C++ 语言 65,212 成员 250,513 内容