gpt4 book ai didi

带有 MySQL 的 C++ 生成文件

转载 作者:行者123 更新时间:2023-11-29 00:31:43 26 4
gpt4 key购买 nike

我正在尝试在 Linux 下构建 C++ 代码。这是我的第一次尝试(否则,我只使用 Windows)。我的代码使用的是 MySQL C API 库,但我在构建它时遇到了问题。我在尝试构建 MainProgram 时得到了这个输出

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 $@


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

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/

关于带有 MySQL 的 C++ 生成文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16211230/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com