1
我想在Linux下構建C++代碼。它是我的第一次嘗試(否則,我只使用Windows)。我的代碼是使用MySQL C API庫,但我有問題構建它。我得到這個輸出而試圖建立MainProgram(主程序)C++ makefile與MySQL
g++ -lstdc++ -c MainProgram.cpp `mysql_config -–libs` -O2 -o MainProgram.obj `mysql_config –-cflags`
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
,並將其鏈接不這樣做,因爲MainProgram.obj缺少
我的makefile文件是這樣的:
CC = g++ CFLAGS = -lm -lstdc++ -Wall -O2
MYSQLCFLAGS = `mysql_config –-cflags`
MYSQLLIBS = `mysql_config -–libs`
BIN = my_program
OBJ = BlockingSocket.obj FTPClient.obj FTPDataTypes.obj FTPFileStatus.obj FTPListParse.obj MyStringAnsi.obj MainProgram.obj
.PHONY: sestav .PHONY: clean
#-----------------------------------------
clean: rm -f *.obj
#-----------------------------------------
sestav: ${BIN}
#-----------------------------------------
$(BIN): $(OBJ) $(OBJ) $(CC) $(CFLAGS) $^ -o [email protected]
#-----------------------------------------
BlockingSocket.obj: ./FtpClient/BlockingSocket.cpp $(CC) -c ./FtpClient/BlockingSocket.cpp -O2 -o BlockingSocket.obj
#-------
FTPClient.obj: ./FtpClient/FTPClient.cpp
$(CC) -c ./FtpClient/FTPClient.cpp -O2 -o FTPClient.obj
FTPDataTypes.obj: ./FtpClient/FTPDataTypes.cpp
$(CC) -c ./FtpClient/FTPDataTypes.cpp -O2 -o FTPDataTypes.obj
FTPFileStatus.obj: ./FtpClient/FTPFileStatus.cpp
$(CC) -c ./FtpClient/FTPFileStatus.cpp -O2 -o FTPFileStatus.obj
FTPListParse.obj: ./FtpClient/FTPListParse.cpp
$(CC) -c ./FtpClient/FTPListParse.cpp -O2 -o FTPListParse.obj
MyStringAnsi.obj: MyStringAnsi.cpp
$(CC) -c MyStringAnsi.cpp -O2 -o MyStringAnsi.obj
MainProgram.obj: MainProgram.cpp
$(CC) -lstdc++ -c MainProgram.cpp $(MYSQLLIBS) -O2 -o MainProgram.obj $(MYSQLCFLAGS)
從建築完成時輸出從零開始:
g++ -c ./FtpClient/BlockingSocket.cpp -O2 -o BlockingSocket.obj
g++ -c ./FtpClient/FTPClient.cpp -O2 -o FTPClient.obj
g++ -c ./FtpClient/FTPDataTypes.cpp -O2 -o FTPDataTypes.obj
g++ -c ./FtpClient/FTPFileStatus.cpp -O2 -o FTPFileStatus.obj
./FtpClient/FTPFileStatus.cpp:136:2: warning: no newline at end of file
g++ -c ./FtpClient/FTPListParse.cpp -O2 -o FTPListParse.obj
g++ -c MyStringAnsi.cpp -O2 -o MyStringAnsi.obj
In file included from MyStringAnsi.cpp:1:
MyString.h:257:7: warning: no newline at end of file
In file included from MyStringAnsi.cpp:3:
./Macros.h:22:7: warning: no newline at end of file
MyStringAnsi.cpp:1350:2: warning: no newline at end of file
MyStringAnsi.cpp: In member function â€void MyStringAnsi::operator+=(char)’:
MyStringAnsi.cpp:1102: warning: NULL used in arithmetic
g++ -lstdc++ -c MainProgram.cpp `mysql_config -–libs` -O2 -o MainProgram.obj `mysql_config –-cflags`
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
g++ -lm -lstdc++ -Wall -O2 BlockingSocket.obj FTPClient.obj FTPDataTypes.obj FTPFileStatus.obj FTPListParse.obj MyStringAnsi.obj MainProgram.obj -o my_program
g++: MainProgram.obj: No such file or directory
make: *** [MainProgram] Error 1
你似乎在你的問題中缺少makefile中的一些換行符。另外,請在從頭開始構建時提供_complete_輸出。 – 2013-04-25 09:36:20
從頭開始構建時添加了完整的輸出。 – 2013-04-25 09:46:48
首先,編譯到一個目標文件時,你不需要庫,也沒有鏈接正在完成。你也應該在shell中自己嘗試失敗的命令,並且檢查'mysql_config'命令實際返回的結果。 – 2013-04-25 09:55:20