链接器错误:"链接器的输入文件未使用的,因为链接尚未完成&QUOT ;,未定义引用的函数在该文件 [英] Linker error: "linker input file unused because linking not done", undefined reference to a function in that file

查看:1747
本文介绍了链接器错误:"链接器的输入文件未使用的,因为链接尚未完成&QUOT ;,未定义引用的函数在该文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与我的文件链接的麻烦。

I'm having trouble with the linking of my files.

基本上,我的程序包括:

Basically, my program consists of:


  • 主程序,第一代

  • 第一代 - 接收输入发送到 str2value
    处理,输出结果 str2value ,打破输入令牌
    使用标记生成器来确定什么样的处理做的每一
    令牌,并将其关闭,以 str2num str2cmd 。然后,它返回一个
    结果数组。

  • str2num - 进行一些处理

  • str2cmd - 同上

  • author.py - 产生一个python脚本 str2cmd.c str2cmd。 ^ h 从头 cmdTable.h

  • The main program, gen1.
  • gen1 - receives input sends to str2value for processing, outputs results str2value, breaks input into tokens using "tokenizer" determines what sort of processing to do to each token, and passes them off to str2num, or str2cmd. It then returns an array of the results.
  • str2num - does some processing
  • str2cmd - ditto
  • author.py - a python script that generates str2cmd.c and str2cmd.h from a header cmdTable.h.

我是pretty确保我有我的权利,包括,我检查了好几次。我还检查了没有条件的#ifndef 错误的标题。

I'm pretty sure I have my includes right, I've checked a couple of times. I've also checked that there are no conditions #ifndef wrong in the headers.

BTW,我知道,GCC不是一个编译器,它是一个文件传递给相应的编译器程序,我知道这一点。

BTW, I am aware that gcc is not a compiler, it's a program that passes a file to the appropriate compiler, I know this.

下面是我的Makefile:

Here is my Makefile:

#CPP = g++ -lserial
CPP = g++ -DTESTMODE
C= gcc
DEFINES = LURC
CFLAGS = -Wall -fshort-enums -D$(DEFINES)
PROJECTFILES = gen1.cpp str2value.o

STR2VALUEFILES = str2value.cpp str2cmd.o str2num.o tokenizer.o str2value.h

gen1 : $(PROJECTFILES)
        $(CPP) $(CFLAGS) -o gen1 $(PROJECTFILES)



str2value.o : $(STR2VALUEFILES)
#       echo "str2value"
        $(CPP) $(CFLAGS) -c $(STR2VALUEFILES)

str2num.o: str2num.cpp  str2value.h str2num.hpp
         $(C) $(CFLAGS) -c $^


tokenizer.o: tokenizer.cpp tokenizer.hpp
        $(CPP) $(CFLAGS) -c $^

str2cmd.o : authorCMDs.py cmdTable.h
        python authorCMDs.py cmdTable.h str2cmd #this uses the gcc -E cmdTable.h -DLURC
        $(C) $(CFLAGS) -c str2cmd.c str2cmd.h

#should add a thing that checks str2cmd.h/.c has not been modified by hand
# i could actually compile them to an doxygen them then delete the source files



.PHONEY: clean
clean:
        rm *.o

.PHONEY: all
all:
        clear
        make clean
        make

下面是输出从我收到化妆所有:

Here is the output I recieve from make all:

make clean
make[1]: Entering directory `/home/frames/LURC/gen1/gen1Source'
rm *.o
make[1]: Leaving directory `/home/frames/LURC/gen1/gen1Source'
make
make[1]: Entering directory `/home/frames/LURC/gen1/gen1Source'
python authorCMDs.py cmdTable.h str2cmd #this uses the gcc -E cmdTable.h -DLURC
str2cmd.c and str2cmd.h, generated from cmdTable.h

gcc  -Wall -fshort-enums -DLURC -c str2cmd.c str2cmd.h
gcc  -Wall -fshort-enums -DLURC -c str2num.cpp str2value.h str2num.hpp
g++ -DTESTMODE -Wall -fshort-enums -DLURC -c tokenizer.cpp tokenizer.hpp
g++ -DTESTMODE -Wall -fshort-enums -DLURC -c str2value.cpp str2cmd.o str2num.o tokenizer.o str2value.h
g++: str2cmd.o: linker input file unused because linking not done
g++: str2num.o: linker input file unused because linking not done
g++: tokenizer.o: linker input file unused because linking not done
g++ -DTESTMODE -Wall -fshort-enums -DLURC -o gen1 gen1.cpp str2value.o
str2value.o: In function `getValue(char*)':
str2value.cpp:(.text+0xbd): undefined reference to `str2cmd(char*)'
str2value.cpp:(.text+0x102): undefined reference to `str2num(char*)'
str2value.o: In function `getAllValues(char*)':
str2value.cpp:(.text+0x164): undefined reference to `tokenizer::tokenizer(char*)'
str2value.cpp:(.text+0x177): undefined reference to `tokenizer::getNumTokens(char const*)'
str2value.cpp:(.text+0x1a9): undefined reference to `tokenizer::getNextToken(char const*)'
str2value.cpp:(.text+0x1e9): undefined reference to `tokenizer::getNumTokens(char const*)'
str2value.cpp:(.text+0x201): undefined reference to `tokenizer::~tokenizer()'
str2value.cpp:(.text+0x25b): undefined reference to `tokenizer::~tokenizer()'
collect2: ld returned 1 exit status
make[1]: *** [gen1] Error 1
make[1]: Leaving directory `/home/frames/LURC/gen1/gen1Source'
make: *** [all] Error 2

有关这是怎么回事有什么建议? STR2VALUESFILES 拥有所有的目标文件,我需要,定义缺失的功能。

Any suggestions about what this is about? STR2VALUESFILES has all the object files I need, to define the missing functions.

推荐答案

我想你混淆了编译器如何把东西放在一起。当您使用 -c 标志,即没有连接完成后,输入的是C ++ code和输出对象code。在的.o 文件从而不与 -c 混合,编译器警告您。从目标文件的符号的的转移到像其他目标文件。

I think you are confused about how the compiler puts things together. When you use -c flag, i.e. no linking is done, the input is C++ code, and the output is object code. The .o files thus don't mix with -c, and compiler warns you about that. Symbols from object file are not moved to other object files like that.

所有的目标文件应该是最后的链接调用,这是不是这里的情况,所以连接(通过 G ++ 称为前端)抱怨缺少符号。

All object files should be on the final linker invocation, which is not the case here, so linker (called via g++ front-end) complains about missing symbols.

下面是一个小例子(呼叫 G ++ 明确为清楚起见):

Here's a small example (calling g++ explicitly for clarity):

PROG ?= myprog
OBJS = worker.o main.o

all: $(PROG)

.cpp.o:
        g++ -Wall -pedantic -ggdb -O2 -c -o $@ $<

$(PROG): $(OBJS)
        g++ -Wall -pedantic -ggdb -O2 -o $@ $(OBJS)

还有 makedepend 自带的工具X11 - 帮助了很多源$ C ​​$ C依赖。您可能还希望看看 -M GCC 选项构建制作规则。

这篇关于链接器错误:&QUOT;链接器的输入文件未使用的,因为链接尚未完成&QUOT ;,未定义引用的函数在该文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆