我已经厌倦了MSVC++ 6以及每个人总是告诉我这是一个糟糕的编译器等等.
所以现在我决定尝试使用vim plus g ++和makefile.这是我的问题; 我有以下makefile:
# This is supposed to be a comment..
CC = g++
# The line above sets the compiler in use..
# The next line sets the compilation flags
CFLAGS=-c -Wall
all: main.exe
main.exe: main.o Accel.o
$(CC) -o main.exe main.o Accel.o
main.o: main.cpp Accel.h
$(CC) $(CFLAGS) main.cpp
Accel.o: Accel.cpp Accel.h
$(CC) $(CFLAGS) Accel.cpp
clean:
del main.exe *.o
Run Code Online (Sandbox Code Playgroud)
这在尝试时会出错make,因为我需要链接到一个Ws2_32.lib所需的Windows库,这是Winsock2.h我include在我的一个.h文件中所需要的.
那我该怎么做?我已经尝试过这个-l选项,但我无法让它发挥作用.它如何与具有空格的路径一起使用?
#include <stdlib.h>
#include <mysql.h>
#include <my_global.h>
int main (int argc, char *argv[])
{
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "127.0.0.1";
char *user = "root";
char *password = "1386";
char *database = "OurDB";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,user, password, database, 0, NULL, 0))
{
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在代码块中收到链接器错误:
undefined reference to mysql_init
Run Code Online (Sandbox Code Playgroud)
我mysql_config --libs在链接器选项和mysql_config --cflags编译器选项中使用过。
我读过某个地方,我应该添加一些库,例如libmysql.lib,但我在PC上找不到此文件(我使用的是Ubuntu 11.04 64bit)。