C++;使用MySQL生成文件 我试图在Linux下构建C++代码。这是我的第一次尝试(否则,我只使用Windows)。我的代码使用的是MySQL C API库,但我在构建它时遇到了问题。我在尝试构建main程序时得到了这个输出 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.

C++;使用MySQL生成文件 我试图在Linux下构建C++代码。这是我的第一次尝试(否则,我只使用Windows)。我的代码使用的是MySQL C API库,但我在构建它时遇到了问题。我在尝试构建main程序时得到了这个输出 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.,c++,mysql,makefile,C++,Mysql,Makefile,然后链接没有完成,因为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 FTPFileSt

然后链接没有完成,因为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 $@


#-----------------------------------------

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
好的。。我解决了这个问题。 首先,正如Joachim在评论中所建议的,我从构建到对象中删除了库 其次,我没有使用mysql_config--libs,而是手动放置路径

现在,makefile编辑如下:

CFLAGS = -lm -lstdc++  -Wall -O2 -L/usr/lib/mysql/ -lmysqlclient

$(CC) -c  MainProgram.cpp -O2 -o MainProgram.obj -I/usr/include/mysql/  
好的。。我解决了这个问题。 首先,正如Joachim在评论中所建议的,我从构建到对象中删除了库 其次,我没有使用mysql_config--libs,而是手动放置路径

现在,makefile编辑如下:

CFLAGS = -lm -lstdc++  -Wall -O2 -L/usr/lib/mysql/ -lmysqlclient

$(CC) -c  MainProgram.cpp -O2 -o MainProgram.obj -I/usr/include/mysql/  

您的问题中的makefile中似乎缺少一些换行符。另外,请在从头开始构建时提供完整的输出。在从头开始构建时添加了完整的输出。首先,在编译到对象文件时,您不需要库,也不需要进行链接。另外,您应该自己在shell中尝试失败的命令,并检查
mysql\u config
命令实际返回的内容。mysql\u config--libs返回:-rdynamic-L/usr/lib/mysql-lmysqlclient-lz-lcrypt-lnsl-lm-L/usr/lib-lssl-lcrypto;mysql_config--cflags返回:-I/usr/include/mysql-g-pipe-Wp,-D_FORTIFY_SOURCE=2-feexceptions-fstack protector--param=ssp buffer size=4-m32-fasynchronous unwind tables-D_GNU_SOURCE-D_FILE_OFFSET_BITS=64-D_LARGEFILE_SOURCE-fno严格的别名-fwrapvYou在您的问题中,makefile中似乎缺少了一些新行。另外,请在从头开始构建时提供完整的输出。在从头开始构建时添加了完整的输出。首先,在编译到对象文件时,您不需要库,也不需要进行链接。另外,您应该自己在shell中尝试失败的命令,并检查
mysql\u config
命令实际返回的内容。mysql\u config--libs返回:-rdynamic-L/usr/lib/mysql-lmysqlclient-lz-lcrypt-lnsl-lm-L/usr/lib-lssl-lcrypto;mysql_config--cflags返回:-I/usr/include/mysql-g-pipe-Wp,-D_FORTIFY_SOURCE=2-feexceptions-fstack protector--param=ssp buffer size=4-m32-fasynchronous unwind tables-D_GNU_SOURCE-D_FILE_OFFSET_BITS=64-D_LARGEFILE_SOURCE-fno严格别名-fwrapv