对..错误的奇怪未定义引用

如何解决对..错误的奇怪未定义引用

| 我正在尝试使用我在Wikipedia上找到的定点数学库,并从Google代码下载它。我试图通过将以下main.c文件添加到其源代码中并将其重新编译为可执行文件来编译一个简单的示例项目。 问题 gcc(实际上是使用代码块v1.0的)抱怨我对库真正定义的函数的未定义引用。一些函数可以工作,而其他函数则会生成“未定义的引用错误”,例如,这是我尝试添加到源文件中的main.c文件。
#include<stdio.h>
#include \"fixmath.h\"
int main()
{
    float num1=6.25f;
    float num2=2.567f;

    fix16_t numfix1=fix16_from_float(num1);
    fix16_t numfix2=fix16_from_float(num2);

    //try out arithmetic on the fixed numbers

    fix16_t simpleAdd= fix16_add(numfix1,numfix2);//(this works !!)no error 

    fix16_t product= fix16_smul(numfix1,numfix2);//undefined reference to \'fix16_smul\'
    fix16_t quotient=fix16_sdiv(numfix1,numfix2);//undefined reference to \'fix16_sdiv\'
    fix16_t sum=fix16_sadd(numfix1,numfix2);//undefined reference to \'fix16_sadd\'
    fix16_t difference=fix16_ssub(numfix1,numfix2);//undefined reference to ....

    //print out the results
    printf(\"the product of %f * %f =%f \\n\",num1,num2,fix16_to_float(product));
    printf(\"the quotient of %f and %f =%f \\n\",fix16_to_float(quotient));
    printf(\"the sum of %f + %f =%f \\n\",fix16_to_float(sum));
    printf(\"the difference of %f - %f =%f \\n\",fix16_to_float(difference));

    //system(\"pause\")
    printf(\"please press any key to continue ...\\n\");
    getchar();

}
EDIT3://同时显示生成文件和构建日志
//build log
Project   : libfixmath
Compiler  : GNU GCC Compiler (called directly)
Directory : C:\\libfixmath\\
--------------------------------------------------------------------------------
Switching to target: dbg
Linking console executable: fixmathexample.exe
obj\\dbg\\main.o: In function `main\':
C:/libfixmath/main.c:14: undefined reference to `fix16_smul\'
C:/libfixmath/main.c:15: undefined reference to `fix16_sdiv\'
C:/libfixmath/main.c:16: undefined reference to `fix16_sadd\'
obj\\dbg\\main.o: In function `fix16_ssub\':
C:/libfixmath/fix16.h:51: undefined reference to `fix16_sadd\'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes,0 seconds)
4 errors,0 warnings
//导出的make文件
###############################################################################
# Makefile automatically generated by Code::Blocks IDE                        #
###############################################################################

# Project:          libfixmath
# Project filename: C:\\libfixmath\\libfixmath.cbp
# Compiler used:    GNU GCC Compiler

### Variables used in this Makefile
dbg_CC=mingw32-gcc.exe
dbg_CPP=mingw32-g++.exe
dbg_LD=mingw32-g++.exe
dbg_LIB=ar.exe
dbg_RESCOMP=windres.exe
rel_CC=mingw32-gcc.exe
rel_CPP=mingw32-g++.exe
rel_LD=mingw32-g++.exe
rel_LIB=ar.exe
rel_RESCOMP=windres.exe

### Compiler/linker options
dbg_GLOBAL_CFLAGS=
dbg_PROJECT_CFLAGS= -DFIXMATH_NO_CACHE -DFIXMATH_NO_64BIT
dbg_GLOBAL_LDFLAGS=
dbg_PROJECT_LDFLAGS=
dbg_GLOBAL_INCS= -IC:/Program\\ Files/CodeBlocks/include
dbg_PROJECT_INCS=
dbg_GLOBAL_LIBDIRS= -LC:/Program\\ Files/CodeBlocks/lib
dbg_PROJECT_LIBDIRS= -LC:/libfixmath/lib
dbg_GLOBAL_LIBS=
dbg_PROJECT_LIBS= C:\\libfixmath\\lib\\libfixmath.a
rel_GLOBAL_CFLAGS=
rel_PROJECT_CFLAGS= -DFIXMATH_NO_CACHE -DFIXMATH_NO_64BIT
rel_GLOBAL_LDFLAGS=
rel_PROJECT_LDFLAGS=
rel_GLOBAL_INCS= -IC:/Program\\ Files/CodeBlocks/include
rel_PROJECT_INCS=
rel_GLOBAL_LIBDIRS= -LC:/Program\\ Files/CodeBlocks/lib
rel_PROJECT_LIBDIRS= -LC:/libfixmath/lib
rel_GLOBAL_LIBS=
rel_PROJECT_LIBS= C:\\libfixmath\\lib\\libfixmath.a

### Targets compiler flags
dbg_CFLAGS= $(dbg_PROJECT_CFLAGS) -Wall -g $(dbg_GLOBAL_CFLAGS)
rel_CFLAGS= $(rel_PROJECT_CFLAGS) -fexpensive-optimizations -O3 -Wall -fomit-frame-pointer $(rel_GLOBAL_CFLAGS)

### Targets linker flags
dbg_LDFLAGS= $(dbg_PROJECT_LDFLAGS) $(dbg_GLOBAL_LDFLAGS)
rel_LDFLAGS= $(rel_PROJECT_LDFLAGS) -s $(rel_GLOBAL_LDFLAGS)

### Targets include directories
dbg_INCS= $(dbg_PROJECT_INCS) $(dbg_GLOBAL_INCS)
rel_INCS= $(rel_PROJECT_INCS) $(rel_GLOBAL_INCS)

### Targets library directories
dbg_LIBDIRS= $(dbg_PROJECT_LIBDIRS) $(dbg_GLOBAL_LIBDIRS)
rel_LIBDIRS= $(rel_PROJECT_LIBDIRS) $(rel_GLOBAL_LIBDIRS)

### Targets libraries
dbg_LIBS= $(dbg_PROJECT_LIBS) $(dbg_GLOBAL_LIBS)
rel_LIBS= $(rel_PROJECT_LIBS) $(rel_GLOBAL_LIBS)

###############################################################################
#         You shouldn\'t need to modify anything beyond this point             #
###############################################################################

### Resources used in this Makefile
dbg_RESOURCE=

### Objects used in this Makefile
dbg_OBJS=obj/dbg/main.o 
dbg_LINKOBJS=$(dbg_OBJS)
dbg_DEPS=.deps/main.d 
rel_OBJS=obj/rel/main.o 
rel_LINKOBJS=$(rel_OBJS)
rel_DEPS=.deps/main.d 

### The targets of this project
dbg_BIN=fixmathexample.exe
rel_BIN=fixmathexample

.PHONY: all all-before all-custom all-after clean clean-custom distclean distclean-custom depend_dbg dbg-before dbg-after depend_rel rel-before rel-after 

all: all-before dbg rel all-after


dist:
    @zip libfixmath.cbp.zip libfixmath.cbp Makefile Makefile fix16.c fix16.h fix16_exp.c fix16_sqrt.c fix16_trig.c fixmath.h fract32.c fract32.h int64.h main.c uint32.c uint32.h 

clean_dbg:
    @echo Cleaning target \"dbg\"...
    @$(RM) $(dbg_BIN) $(dbg_OBJS) $(dbg_RESOURCE) 

distclean_dbg:
    @echo Dist-cleaning target \"dbg\"...
    @$(RM) $(dbg_BIN) $(dbg_OBJS) $(dbg_DEPS) $(dbg_RESOURCE) 

clean_rel:
    @echo Cleaning target \"rel\"...
    @$(RM) $(rel_BIN) $(rel_OBJS) $(rel_RESOURCE) 

distclean_rel:
    @echo Dist-cleaning target \"rel\"...
    @$(RM) $(rel_BIN) $(rel_OBJS) $(rel_DEPS) $(rel_RESOURCE) 

clean: clean_dbg clean_rel 

distclean: distclean_dbg distclean_rel 

depend_dbg_DIRS:
    -@if not exist \".deps\\.\" mkdir \".deps\"

depend_dbg: depend_dbg_DIRS $(dbg_DEPS)

depend_rel_DIRS:
    -@if not exist \".deps\\.\" mkdir \".deps\"

depend_rel: depend_rel_DIRS $(rel_DEPS)

depend: depend_dbg depend_rel

dbg_DIRS:
    -@if not exist \"obj\\.\" mkdir \"obj\"
    -@if not exist \"obj\\dbg\\.\" mkdir \"obj\\dbg\"

dbg: depend_dbg dbg_DIRS dbg-before $(dbg_BIN) dbg-after

$(dbg_BIN): $(dbg_LINKOBJS) $(dbg_RESOURCE)
    @echo Linking executable \"fixmathexample.exe\"...
    @$(dbg_LD) $(dbg_LIBDIRS) -o $(dbg_BIN) $(dbg_LINKOBJS) $(dbg_RESOURCE) $(dbg_LDFLAGS) $(dbg_LIBS)

rel_DIRS:
    -@if not exist \"obj\\.\" mkdir \"obj\"
    -@if not exist \"obj\\rel\\.\" mkdir \"obj\\rel\"

rel: depend_rel rel_DIRS rel-before $(rel_BIN) rel-after

$(rel_BIN): $(rel_LINKOBJS) $(rel_RESOURCE)
    @echo Linking executable \"fixmathexample\"...
    @$(rel_LD) $(rel_LIBDIRS) -o $(rel_BIN) $(rel_LINKOBJS) $(rel_RESOURCE) $(rel_LDFLAGS) $(rel_LIBS)


.deps/main.d: main.c
    @echo Calculating dependencies for \"main.c\"...
    @$(dbg_CC) -MM $(dbg_CFLAGS) -MF .deps/main.d -MT obj/dbg/main.o,obj/rel/main.o $(dbg_INCS) main.c

obj/dbg/main.o: .deps/main.d
    @echo Compiling \"main.c\"...
    @$(dbg_CC) $(dbg_CFLAGS) $(dbg_INCS) -c main.c -o obj/dbg/main.o


obj/rel/main.o: main.c
    @echo Compiling \"main.c\"...
    @$(rel_CC) $(rel_CFLAGS) $(rel_INCS) -c main.c -o obj/rel/main.o
    

解决方法

        您确定已链接到库吗?可能起作用的函数是头文件中定义的内联函数,因此您具有它们的定义,而其他函数的定义位于.lib文件中,您需要对其进行链接。     ,        您是对的,库确实提供了这些,但是\“ undefined reference \”是链接器错误;您必须将库链接到编译的目标代码。仅包含头文件是不够的,仅包含库提供的符号声明即可。 我想象Code :: Blocks \的项目经理有一个用于指定其他库的条目。 在这种情况下,
fix16_add
有效,因为它在头文件中被完全定义为
inline
代码。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)&gt; insert overwrite table dwd_trade_cart_add_inc &gt; select data.id, &gt; data.user_id, &gt; data.course_id, &gt; date_format(
错误1 hive (edu)&gt; insert into huanhuan values(1,&#39;haoge&#39;); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive&gt; show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 &lt;configuration&gt; &lt;property&gt; &lt;name&gt;yarn.nodemanager.res