jolr 发表于 2012-10-30 11:10

【救助】FreeBSD下用C/C++联Redis

救助有经验的朋友,我在FreeBSD下使用C++来联Redis,但总是编译不成功,我已经安装过boost,希望大家不吝赐教,感谢# make
g++ -c -O2 -pipetest_client.cpp
In file included from test_client.cpp:1:
redisclient.h:45:35: error: boost/concept_check.hpp: No such file or directory
redisclient.h:46:34: error: boost/lexical_cast.hpp: No such file or directory
redisclient.h:47:37: error: boost/functional/hash.hpp: No such file or directory
redisclient.h:48:29: error: boost/foreach.hpp: No such file or directory
redisclient.h:49:34: error: boost/thread/mutex.hpp: No such file or directory
redisclient.h:50:47: error: boost/thread/condition_variable.hpp: No such file or directory
redisclient.h:51:28: error: boost/random.hpp: No such file or directory
redisclient.h:52:29: error: boost/cstdint.hpp: No such file or directory
redisclient.h:53:48: error: boost/date_time/posix_time/ptime.hpp: No such file or directory
redisclient.h:54:59: error: boost/date_time/posix_time/posix_time_types.hpp: No such file or directory
redisclient.h:55:30: error: boost/optional.hpp: No such file or directory
redisclient.h:56:29: error: boost/variant.hpp: No such file or directory
test_client.cpp:4:31: error: boost/date_time.hpp: No such file or directory
In file included from test_client.cpp:1:
redisclient.h:107: error: 'boost' has not been declared
redisclient.h:107: error: ISO C++ forbids declaration of 'uint16_t' with no type
redisclient.h:107: error: expected ';' before 'port'
redisclient.h: In constructor 'redis::connection_data::connection_data(const std::string&, uint16_t, int)':
redisclient.h:90: error: class 'redis::connection_data' does not have any field named 'port'
redisclient.h: In member function 'bool redis::connection_data::operator==(const redis::connection_data&) const':
redisclient.h:98: error: 'port' was not declared in this scope
redisclient.h:98: error: 'const struct redis::connection_data' has no member named 'port'
redisclient.h: At global scope:
redisclient.h:273: error: 'boost' has not been declared
redisclient.h:273: error: ISO C++ forbids declaration of 'optional' with no type
redisclient.h:273: error: expected ';' before '<' token
.....................

stephen_du 发表于 2012-10-30 14:14

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 static/image/common/back.gif
一般不在/usr/include下面,就在/usr/local/include下面


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

using namespace std;

int main() {
    MYSQL mysql;
    MYSQL_RES * mysql_ret;
    MYSQL_ROW mysql_row;
    int ret;

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

    } else {
      mysql_ret   =   mysql_store_result(&mysql);
      while(mysql_row   =   mysql_fetch_row(mysql_ret)){
            //printf( "%s\t%s\t%s\t%s\t%s\t%s\n ",mysql_row,mysql_row,mysql_row,mysql_row,mysql_row,mysql_row);
            cout << mysql_row << endl;
      }
    }
    mysql_close(&mysql);
}

jolr 发表于 2012-10-31 14:25

我在FreeBSD下使用C++联mysql搞定了,使用编译命令是g++ mysql.cpp -I /usr/local/include -L /usr/local/lib/mysql -l mysqlclient
页: [1]
查看完整版本: 【救助】FreeBSD下用C/C++联Redis