C 奇怪的未定义引用。。错误

C 奇怪的未定义引用。。错误,c,compiler-errors,fixed-point,C,Compiler Errors,Fixed Point,我正在尝试一个我找到并下载的定点数学库我试图编译一个简单的示例项目,将下面的main.c文件添加到源代码中,并将整个项目重新编译为可执行文件。 问题 gcc(我实际上使用的是代码块v1.0)抱怨未定义的函数引用一些函数可以工作其他函数生成“未定义的引用错误”例如,这是我试图添加到源文件的主.c文件 #include<stdio.h> #include "fixmath.h" int main() { float num1=6.25f; float num2=2.567

我正在尝试一个我找到并下载的定点数学库
我试图编译一个简单的示例项目,将下面的main.c文件添加到源代码中,并将整个项目重新编译为可执行文件。 问题
gcc(我实际上使用的是代码块v1.0)抱怨未定义的函数引用一些函数可以工作其他函数生成“未定义的引用错误”例如,
这是我试图添加到源文件的主.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",num1,num2,fix16_to_float(quotient));
    printf("the sum of %f + %f =%f \n",num1,num2,fix16_to_float(sum));
    printf("the difference of %f - %f =%f \n",num1,num2,fix16_to_float(difference));

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

}
//导出的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文件中。

您确定已链接到库吗?可能工作的函数是头文件中定义的内联函数,因此您有它们的定义,其他函数的定义在需要链接的.lib文件中。

您是对的,库确实提供了这些函数,但“未定义引用”是链接器错误;您必须将库链接到已编译的目标代码。仅包含标头是不够的,因为它仅包含库提供的符号声明

我想象Code::Blocks的项目管理器有一个用于指定附加库的条目


fix16\u add
在这种情况下起作用,因为它在头文件中完全定义为
内联
代码。

你说得对,库确实提供了这些,但“未定义引用”是链接器错误;您必须将库链接到已编译的目标代码。仅包含标头是不够的,因为它仅包含库提供的符号声明

我想象Code::Blocks的项目管理器有一个用于指定附加库的条目


fix16\u add
在这种情况下起作用,因为它在头文件中完全定义为
inline
代码。

我想我有。我将发布make文件,如果它有帮助当前版本的Code::Blocks是v10.05-你真的在使用v1.0吗!?首先,我建议您升级它:makefile似乎确实引用了libfixmath,但似乎是fixmathexample.exe和libfixmath构建的奇怪组合(例如,
rel_-BIN
dbg_-BIN
目标不同)。啊,makefile仍然很有用,尤其是因为构建日志不是逐字链接器输出,并且不包括实际发出的链接器命令行。有趣的是,您先前发布的makefile发出了字符串“Linking executable”,但您的日志中有“Linking console executable”,这让我相信您显示的makefile不是此版本中的makefile。您是对的。我一直在尝试应用建议的更改。我想我已经做到了。我将发布make文件,如果它有帮助当前版本的Code::Blocks是v10.05-你真的在使用v1.0吗!?首先,我建议您升级它:makefile似乎确实引用了libfixmath,但似乎是fixmathexample.exe和libfixmath构建的奇怪组合(例如,
rel_-BIN
dbg_-BIN
目标不同)。啊,makefile仍然很有用,尤其是因为构建日志不是逐字链接器输出,并且不包括实际发出的链接器命令行。有趣的是,您先前发布的makefile发出了字符串“Linking executable”,但您的日志中有“Linking console executable”,这让我相信您显示的makefile不是此版本中的makefile。您是对的。我一直在尝试应用建议的更改。
###############################################################################
# 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