【发布时间】:2014-05-22 08:47:04
【问题描述】:
我正在尝试使用以下 make 文件编译我的程序。我在互联网上找到了一个模板,我正在尝试使用它。我只修改了# Main entry point之前的东西
制作文件
# Define executable name
BIN = CLI_DeskManager
# Define source files
SRCS = main.cpp shell.cpp
# Define header file paths
INCPATH = -I./ -I/usr/include/X11/exensions -I/usr/include/X11 -I/home/julien/Documents/DeskManagerDll
# Define the -L library path(s)
LDFLAGS = -L/usr/X11R6/lib -L/home/julien/Documents/DeskManagerDll
# Define the -l library name(s)
LIBS = -lX11 -lXext -Wl,--no-as-needed -lDeskManager -lpthread
# Only in special cases should anything be edited below this line
OBJS = $(CPP_SRCS:.cpp=.o)
CXXFLAGS = -Wall -ansi -pedantic -std=c++11 -pthread
DEP_FILE = .depend
# Main entry point
#
all: depend $(BIN)
# For linking object file(s) to produce the executable
#
$(BIN): $(OBJS)
@echo Linking $@
@$(CXX) $^ $(LDFLAGS) $(LIBS) -o $@
# For compiling source file(s)
#
.cpp.o:
@echo Compiling $<
@$(CXX) -c $(CXXFLAGS) $(INCPATH) $<
# For cleaning up the project
#
clean:
$(RM) $(OBJS)
distclean: clean
$(RM) $(BIN)
$(RM) $(DEP_FILE)
# For determining source file dependencies
#
depend: $(DEP_FILE)
@touch $(DEP_FILE)
$(DEP_FILE):
@echo Generating dependencies in $@
@-$(CXX) -E -MM $(CXXFLAGS) $(INCPATH) $(SRCS) >> $(DEP_FILE)
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring distclean,$(MAKECMDGOALS)))
-include $(DEP_FILE)
endif
endif
错误
但是我有很多类似下面的错误
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
但是on this threadsoru 说重要的是:
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
make: *** [CLI_DeskManager] Error 1
其他信息
我已经用 Code::blocks 成功编译了,这是构建日志。
g++ -Wall -fexceptions -std=c++11 -g -pthread -I/usr/include/X11/extensions -I/usr/include/X11 -I../DeskManagerDll -c /home/julien/Documents/CommandLineInterface_DeskManager/main.cpp -o obj/Debug/main.o
g++ -Wall -fexceptions -std=c++11 -g -pthread -I/usr/include/X11/extensions -I/usr/include/X11 -I../DeskManagerDll -c /home/julien/Documents/CommandLineInterface_DeskManager/shell.cpp -o obj/Debug/shell.o
g++ -L-L/usr/lib/i386-linux-gnu -o bin/Debug/CommandLineInterface_DeskManager obj/Debug/main.o obj/Debug/shell.o -L/usr/X11R6/lib -lX11 -lXext -Wl,--no-as-needed -lpthread /home/julien/Documents/DeskManagerDll/bin/Debug/libDeskManagerDll.so
我在 StackOverflow 上找到了答案,但我不明白。
我做错了什么?
谢谢。
更新 Lijat 回答后
推荐修改后的Makefile
# Define executable name
BIN = CLI_DeskManager
# Define source files
SRCS = main.cpp shell.cpp
# Define header file paths
INCPATH = -I./ -I/usr/include/X11/exensions -I/usr/include/X11 -I/home/julien/Documents/DeskManagerDll
# Define the -L library path(s)
LDFLAGS = -L/usr/X11R6/lib -L/home/julien/Documents/DeskManagerDll/bin/Debug
# Define the -l library name(s)
LIBS = -lX11 -lXext -Wl,--no-as-needed -lDeskManagerDll -lpthread
# Only in special cases should anything be edited below this line
OBJS = $(CPP_SRCS:.cpp=.o)
CXXFLAGS = -Wall -ansi -pedantic -std=c++11 -pthread
DEP_FILE = .depend
# Main entry point
#
all: depend $(BIN)
# For linking object file(s) to produce the executable
#
$(BIN): $(OBJS)
echo Linking $@
$(CXX) $^ $(LDFLAGS) $(LIBS) -o $@
# For compiling source file(s)
#
.cpp.o:
echo Compiling $<
$(CXX) -c $(CXXFLAGS) $(INCPATH) $< -o $@
# For cleaning up the project
#
clean:
$(RM) $(OBJS)
distclean: clean
$(RM) $(BIN)
$(RM) $(DEP_FILE)
# For determining source file dependencies
#
depend: $(DEP_FILE)
touch $(DEP_FILE)
$(DEP_FILE):
echo Generating dependencies in $@
-$(CXX) -E -MM $(CXXFLAGS) $(INCPATH) $(SRCS) >> $(DEP_FILE)
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
ifeq (,$(findstring distclean,$(MAKECMDGOALS)))
-include $(DEP_FILE)
endif
endif
完整的输出。我很抱歉它是法语的。我的问题的第一部分只翻译了两个不同的句子。
julien@julien-VirtualBox:~/Documents/CommandLineInterface_DeskManager$ make
touch .depend
echo Linking CLI_DeskManager
Linking CLI_DeskManager
g++ -L/usr/X11R6/lib -L/home/julien/Documents/DeskManagerDll/bin/Debug -lX11 -lXext -Wl,--no-as-needed -lDeskManagerDll -lpthread -o CLI_DeskManager
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 0 a un index de symbole 11 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 1 a un index de symbole 12 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 2 a un index de symbole 2 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 3 a un index de symbole 2 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 4 a un index de symbole 11 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 5 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 6 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 7 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 8 a un index de symbole 12 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 9 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 10 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 11 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 12 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 13 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 14 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 15 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 16 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 17 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 18 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 19 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 20 a un index de symbole 13 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_info): réadressage 21 a un index de symbole 22 invalide
/usr/bin/ld: /usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_line): réadressage 0 a un index de symbole 2 invalide
/usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: dans la fonction « _start »:
(.text+0x18): référence indéfinie vers « main »
collect2: error: ld returned 1 exit status
make: *** [CLI_DeskManager] Erreur 1
【问题讨论】: