首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

C++与MySQL的冲突

当在C++代码中,直接引用MySQL头文件时,可能会遇到如下错误: In file included from /usr/include/c++/4.1.0/bits/char_traits.h:46,                  from /usr/include/c++/4.1.0/string:46, /usr/include/c++/4.1.0/bits/stl_algobase.h:92:28: error: macro "swap" requires 3 arguments, but only 2 given /usr/include/c++/4.1.0/bits/stl_algobase.h:127:26: error: macro "swap" requires 3 arguments, but only 2 given /usr/include/c++/4.1.0/bits/vector.tcc:176:20: error: macro "swap" requires 3 arguments, but only 1 given /usr/include/c++/4.1.0/cctype:70: error: '::isalnum' has not been declared /usr/include/c++/4.1.0/cctype:71: error: '::isalpha' has not been declared /usr/include/c++/4.1.0/cctype:72: error: '::iscntrl' has not been declared /usr/include/c++/4.1.0/cctype:73: error: '::isdigit' has not been declared /usr/include/c++/4.1.0/cctype:74: error: '::isgraph' has not been declared /usr/include/c++/4.1.0/cctype:75: error: '::islower' has not been declared /usr/include/c++/4.1.0/cctype:76: error: '::isprint' has not been declared /usr/include/c++/4.1.0/cctype:77: error: '::ispunct' has not been declared /usr/include/c++/4.1.0/cctype:78: error: '::isspace' has not been declared /usr/include/c++/4.1.0/cctype:79: error: '::isupper' has not been declared /usr/include/c++/4.1.0/cctype:80: error: '::isxdigit' has not been declared /usr/include/c++/4.1.0/cctype:81: error: '::tolower' has not been declared /usr/include/c++/4.1.0/cctype:82: error: '::toupper' has not been declared 解决办法: 尽量对MySQL进行二次包装,让调用者看不到MySQL头文件,如在CPP中包含: #include #include #include 在头文件中只进行引用声明: struct st_mysql; struct st_mysql_res; typedef long num_t; typedef char ** MYSQL_ROW;  /** return data as array of strings */ 不要在头文件直接include到MySQL的头文件,而且保证只在一个CPP文件中有对MySQL文件的include,否则你可能遇到很多莫名其妙的编译错误,如果不想到这一点,即使花一天时间也未必能找到错误原因。

03
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    什么是实例内部类 Instance inner class有什么语法?

    重要语法:马克-to-win:1)实例内部类一定得有个外层类的实例和它绑定在一起,所以可以用This指针。所以必须先实例化外层类之后才能再实例化内部类。(生活中的例子就是子宫和胚胎(不算试管婴儿!))2)语法规定:实例内部类不能有静态的属性或方法,为什么?因为没有外层类的实例就不应该有实例内部类的任何东西存在,包括内部类的静态属性,但静态属性应该在main方法执行时创建,这样就会产生矛盾,所以规定实例内部类不能有静态的属性或方法。马克-to-win:2)既然每个内部类实例都可以改变他们共同的外层类的静态属性或实例属性,他们成为内部类实例们可以交互的地方。(下例中的shell_x,在不断增长。)

    03

    Thrift编译错误('::malloc' has not been declared)

    问题版本:0.9.0 make[4]: Entering directory `/tmp/X/thrift-0.9.0/lib/cpp' /bin/sh ../../libtool  --tag=CXX   --mode=compile g++ -DHAVE_CONFIG_H -I. -I../..  -I/usr/local/thirdparty/boost/include -I./src -I./src/thrift -I/usr/local/thirdparty/openssl/include -Wall -g -O2 -MT Thrift.lo -MD -MP -MF .deps/Thrift.Tpo -c -o Thrift.lo `test -f 'src/thrift/Thrift.cpp' || echo './'`src/thrift/Thrift.cpp libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I../.. -I/usr/local/thirdparty/boost/include -I./src -I./src/thrift -I/usr/local/thirdparty/openssl/include -Wall -g -O2 -MT Thrift.lo -MD -MP -MF .deps/Thrift.Tpo -c src/thrift/Thrift.cpp  -fPIC -DPIC -o .libs/Thrift.o In file included from src/thrift/Thrift.cpp:22: /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/cstdlib:119: error: '::malloc' has not been declared /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/cstdlib:127: error: '::realloc' has not been declared src/thrift/Thrift.cpp: In member function 'void apache::thrift::TOutput::printf(const char*, ...)': src/thrift/Thrift.cpp:46: error: 'malloc' was not declared in this scope make[4]: *** [Thrift.lo] Error 1 解决方法: 在成功执行configure后(在未执行configure之前找不到下列两行),修改与configure同目录下的config.h文件,将文件中的如下两行注释掉: #define malloc rpl_malloc #define realloc rpl_realloc 附1:安装Thrift命令行: ./configure --prefix=/usr/local/thirdparty/thrift-0.9.0 --with-boost=/usr/local/thirdparty/boost --with-libevent=/usr/local/thirdparty/libevent CPPFLAGS="-I/usr/local/thirdparty/openssl/include" LDFLAGS="-ldl -L/usr/local/thirdparty/openssl/lib" --with-qt4=no --with-c_glib=no --with-csharp=no --with-erlang=no --with-perl=no --with-ruby=no --with-haskell=no --with-go=no --with-d 当OpenSSL未以默认安装目录时,请注意上面的用法。 附2:相关博文: (安装thrift时,注意openssl参数)http://blog.chinaunix.net/uid-20682147-id-3399150.html 如果在使用Thrift时,编译遇到类似“TTransport.h:107: error: 'uint32_t' does not name a type”的错误,只需要在Thrift.h文件中增加一行:#include 。 Thrift.h文件位于make install后的include目录下,如果不知道在哪,可以使用find命令查找。

    03
    领券