有关于OpenGL的实例教程么?
代码:
.PHONY:clean
dm:main.o MySQLRecordSet.o
g++ -o $@ $^ -L /usr/lib/mysql/*.a -lz
main.o:main.cpp
g++ -c $<
MySQLRecordSet.o:MySQLRecordSet.cpp MySQLRecordSet.h
g++ -c $<
clean:
rm -rf *.o dm
dm:main.o MySQLRecordSet.o
g++ -o $@ $^ -L /usr/lib/mysql/*.a -lz
main.o:main.cpp
g++ -c $<
MySQLRecordSet.o:MySQLRecordSet.cpp MySQLRecordSet.h
g++ -c $<
clean:
rm -rf *.o dm
g++ -o $@ $^ -L /usr/lib/mysql/*.a -lz
不行 提示mysql.h找不到这个文件
改成
g++ $(mysql_config --cflags) connect.c -o connect $(mysql_config --libs)这样可以
我单独写一个 用这个局话编译就可以 这样怎么改呀 高人指点下
作者: rnon 发布时间: 2009-05-06
引用:
g++ -o $@ $^ -L /usr/lib/mysql/*.a -lz
没加 -I ? 假设mysql头文件路径为/usr/include/mysql, 则
代码:
g++ -o $@ $^ -I/usr/include/mysql -L /usr/lib/mysql/*.a -lz
试试看吧。
作者: kwarph 发布时间: 2009-05-06
代码:
g++ -c main.cpp
在包含自 main.cpp:1 的文件中:
MysqlRecordSet.h:4:19: 错误: mysql.h:没有该文件或目录
In file included from main.cpp:1:
MysqlRecordSet.h:21: 错误: ISO C++ 不允许声明无类型的‘MYSQL’
MysqlRecordSet.h:21: 错误: expected ‘;’ before ‘*’ token
MysqlRecordSet.h:24: 错误: ISO C++ 不允许声明无类型的‘MYSQL’
MysqlRecordSet.h:24: 错误: expected ‘;’ before ‘*’ token
在包含自 main.cpp:1 的文件中:
MysqlRecordSet.h:4:19: 错误: mysql.h:没有该文件或目录
In file included from main.cpp:1:
MysqlRecordSet.h:21: 错误: ISO C++ 不允许声明无类型的‘MYSQL’
MysqlRecordSet.h:21: 错误: expected ‘;’ before ‘*’ token
MysqlRecordSet.h:24: 错误: ISO C++ 不允许声明无类型的‘MYSQL’
MysqlRecordSet.h:24: 错误: expected ‘;’ before ‘*’ token
还是提示这个 奇怪了
我单独写个可以 可是用Makefile就不行
单独的如下
代码:
/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "123456"; /* 此处改成你的密码 */
char *database = "mysql";
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));
return 0;
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
return 0;
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
return 1;
}
#include <mysql.h>
#include <stdio.h>
int main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
char *password = "123456"; /* 此处改成你的密码 */
char *database = "mysql";
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));
return 0;
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
return 0;
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
return 1;
}
g++ $(mysql_config --cflags) connect.c -o connect $(mysql_config --libs)这样编译就OK了
作者: rnon 发布时间: 2009-05-07
我没有用过mysql客户端编程的API,刚才查了一下,才知道 mysql_config这个命令能做的不仅仅是添加一个 -I 那么简单,你还是得使用 mysql_config --cflags 或 mysql_config --libs 或 mysql_config --include ,避免有遗漏的配置。
作者: kwarph 发布时间: 2009-05-07
g++ $(mysql_config --cflags) connect.c -o connect $(mysql_config --libs)
我把所有的文件整到一个文件 用上面那个编译命令是可以的
用makefile写就是不行 不知道为什么
问了 要加上反引号 可是我还是不行 奇怪了
老是提示Mysql.h文件不存在
我把所有的文件整到一个文件 用上面那个编译命令是可以的
用makefile写就是不行 不知道为什么
代码:
.PHONY:clean
dm:main.o MySQLRecordSet.o
g++ $`(mysql_config --cflags)` -o $@ $^ $`(mysql_config --libs)`
main.o:main.cpp
g++ -c $<
MySQLRecordSet.o:MySQLRecordSet.cpp MySQLRecordSet.h
g++ -c $<
clean:
rm -rf *.o dm
dm:main.o MySQLRecordSet.o
g++ $`(mysql_config --cflags)` -o $@ $^ $`(mysql_config --libs)`
main.o:main.cpp
g++ -c $<
MySQLRecordSet.o:MySQLRecordSet.cpp MySQLRecordSet.h
g++ -c $<
clean:
rm -rf *.o dm
问了 要加上反引号 可是我还是不行 奇怪了
老是提示Mysql.h文件不存在
作者: rnon 发布时间: 2009-05-07
作者: rnon 发布时间: 2009-05-08
去掉$,下面这句试试:
或不要括号:
代码:
g++ `(mysql_config --cflags)` -o $@ $^ `(mysql_config --libs)`
或不要括号:
代码:
g++ `mysql_config --cflags` -o $@ $^ `mysql_config --libs`
作者: kwarph 发布时间: 2009-05-09
kwarph 写道:
去掉$,下面这句试试:
或不要括号:
代码:
g++ `(mysql_config --cflags)` -o $@ $^ `(mysql_config --libs)`
或不要括号:
代码:
g++ `mysql_config --cflags` -o $@ $^ `mysql_config --libs`
还是提示不存在mysql.h
作者: rnon 发布时间: 2009-05-11
SQLCFG = /usr/bin/mysql_config
$(CXX) $(CPPFLAGS) $(CFLAGS) `$(SQLCFG) --cflags` $^ -o $@ `$(SQLCFG) --libs`
$(CXX) $(CPPFLAGS) $(CFLAGS) `$(SQLCFG) --cflags` $^ -o $@ `$(SQLCFG) --libs`
作者: wqlineky1 发布时间: 2011-03-27