Chinaunix

标题: 【救助】FreeBSD下用C/C++联Redis [打印本页]

作者: jolr    时间: 2012-10-30 11:10
标题: 【救助】FreeBSD下用C/C++联Redis
救助有经验的朋友,我在FreeBSD下使用C++来联Redis,但总是编译不成功,我已经安装过boost,希望大家不吝赐教,感谢
  1. [root@jiangpo /home/Jolr/redis]# make
  2. g++ -c -O2 -pipe  test_client.cpp
  3. In file included from test_client.cpp:1:
  4. redisclient.h:45:35: error: boost/concept_check.hpp: No such file or directory
  5. redisclient.h:46:34: error: boost/lexical_cast.hpp: No such file or directory
  6. redisclient.h:47:37: error: boost/functional/hash.hpp: No such file or directory
  7. redisclient.h:48:29: error: boost/foreach.hpp: No such file or directory
  8. redisclient.h:49:34: error: boost/thread/mutex.hpp: No such file or directory
  9. redisclient.h:50:47: error: boost/thread/condition_variable.hpp: No such file or directory
  10. redisclient.h:51:28: error: boost/random.hpp: No such file or directory
  11. redisclient.h:52:29: error: boost/cstdint.hpp: No such file or directory
  12. redisclient.h:53:48: error: boost/date_time/posix_time/ptime.hpp: No such file or directory
  13. redisclient.h:54:59: error: boost/date_time/posix_time/posix_time_types.hpp: No such file or directory
  14. redisclient.h:55:30: error: boost/optional.hpp: No such file or directory
  15. redisclient.h:56:29: error: boost/variant.hpp: No such file or directory
  16. test_client.cpp:4:31: error: boost/date_time.hpp: No such file or directory
  17. In file included from test_client.cpp:1:
  18. redisclient.h:107: error: 'boost' has not been declared
  19. redisclient.h:107: error: ISO C++ forbids declaration of 'uint16_t' with no type
  20. redisclient.h:107: error: expected ';' before 'port'
  21. redisclient.h: In constructor 'redis::connection_data::connection_data(const std::string&, uint16_t, int)':
  22. redisclient.h:90: error: class 'redis::connection_data' does not have any field named 'port'
  23. redisclient.h: In member function 'bool redis::connection_data::operator==(const redis::connection_data&) const':
  24. redisclient.h:98: error: 'port' was not declared in this scope
  25. redisclient.h:98: error: 'const struct redis::connection_data' has no member named 'port'
  26. redisclient.h: At global scope:
  27. redisclient.h:273: error: 'boost' has not been declared
  28. redisclient.h:273: error: ISO C++ forbids declaration of 'optional' with no type
  29. redisclient.h:273: error: expected ';' before '<' token
  30. .....................
复制代码

作者: stephen_du    时间: 2012-10-30 14:14
回复 1# jolr


   

编译的时候加-I指向boot头文件的目录;-L指向对应的so目录
作者: jolr    时间: 2012-10-30 22:21
回复 2# stephen_du

我是使用ports安装的,都不知道把他们装到哪了。

   
作者: egmkang    时间: 2012-10-30 22:46
一般不在/usr/include下面,就在/usr/local/include下面
作者: jolr    时间: 2012-10-31 13:15
egmkang 发表于 2012-10-30 22:46
一般不在/usr/include下面,就在/usr/local/include下面



谢谢 egmkang指点,可以告诉我具体怎么打命令么,make和 g++怎么指路径?
我在使用C++联mysql时也遇到类似问题,使用的是g++命令编译,但不知道怎么指定目录,我C++基本比较差,

  1. #include <iostream>
  2. #include <include/mysql.h>
  3. #include <string>

  4. using namespace std;

  5. int main() {
  6.     MYSQL mysql;
  7.     MYSQL_RES * mysql_ret;
  8.     MYSQL_ROW mysql_row;
  9.     int ret;

  10.     mysql_init(&mysql);
  11.     mysql_real_connect(&mysql, "localhost", "root", "123321", "mysql", 3306, NULL, 0);
  12.     string sql = "select * from mysql";
  13.     ret = mysql_query(&mysql, "select * from user");
  14.     if (ret) {
  15.         //cout << "OK" << endl;

  16.     } else {
  17.         mysql_ret   =   mysql_store_result(&mysql);
  18.         while(mysql_row   =   mysql_fetch_row(mysql_ret))  {
  19.             //printf( "%s\t%s\t%s\t%s\t%s\t%s\n ",mysql_row[0],mysql_row[1],mysql_row[2],mysql_row[3],mysql_row[4],mysql_row[5]);
  20.             cout << mysql_row[1] << endl;
  21.         }
  22.     }
  23.     mysql_close(&mysql);
  24. }
复制代码

作者: jolr    时间: 2012-10-31 14:25
我在FreeBSD下使用C++联mysql搞定了,使用编译命令是
  1. g++ mysql.cpp -I /usr/local/include -L /usr/local/lib/mysql -l mysqlclient
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2