c++ - 使用 map 功能 ubuntu

标签 c++ ubuntu

我正在尝试在 ubuntu 中编译以下代码

#include <unordered_map.h>
typedef unsigned int key_type;  // fine, has < , ==, and std::hash
typedef std::map<key_type, some_value_type> my_map;

使用这个命令

g++ -Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX -I/usr/include/ -I/usr/include/c++/4.5/bits/ main.c -o program

我得到了这个错误

1234@(none:/usr/local/src/testing$ make
g++ -Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX -I/usr/include/ -I/usr/include/c++/4.5/bits/ main.c -o program
In file included from main.c:5:0:
/usr/include/c++/4.5/bits/unordered_map.h:33:32: error: expected constructor, destructor, or type conversion before ‘(’ token
make: *** [all] Error 1

这是 map.h 的定位

1234@(none):/usr/local/src/testing$ 定位 map.h

/usr/include/c++/4.5/bits/STL_map.h

/usr/include/c++/4.5/bits/STL_multimap.h

/usr/include/c++/4.5/bits/unordered_map.h

/usr/include/c++/4.5/debug/map.h

/usr/include/c++/4.5/debug/multimap.h

/usr/include/c++/4.5/profile/map.h

/usr/include/c++/4.5/profile/multimap.h

/usr/include/c++/4.5/profile/impl/profiler_map_to_unordered_map.h

/usr/include/c++/4.5/tr1/unordered_map.h

此外,我还有其他用于 mysql 的 studd,我将使用它,但 main 仅返回 0;

最佳答案

如果您没有完全搞砸您的编译器设置,您应该不需要传递那么多选项。您应该可以删除 -I/usr/include/-I/usr/include/c++/4.5/bits/

g++ -Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient \
 -I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing \
 -DUNIV_LINUX -DUNIV_LINUX main.c -o program

此外,由于您调整了包含路径,因此您能够看到不应直接包含的实现文件 unordered_map.h。而是包括

#include <unordered_map>
// for C++0x

#include <tr1/unordered_map>
// for C++98

通常,C++ 的“标准库”头文件名称中没有 .h。 C 库头文件有它(例如 math.h),但您会获得一个附加版本,其声明正确包装在标准命名空间中。这些 header 以 c 开头,例如cmath.

关于c++ - 使用 map 功能 ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6875683/

相关文章:

angular - 子目录中的 Laravel

c++ - 让 RInside 示例使用额外的链接器选项 -framework

Ubuntu 18.04 升级和 Cassandra 连接错误

ubuntu - Elasticsearch 问题-我使用命令 curl -X GET "localhost:9200",不工作 4 curl -X GET "public_ipv4_of_ubuntu_server:9200"

php - 不使用 curl 安装 Composer(本地)

ubuntu - 如何构建debian包并自动获取所有依赖库

c++ - C++ 类中使用的默认值

c++ - 收集有关在程序中实例化哪些模板变体的信息

c++ - NRVO 什么时候开始?需要满足哪些要求?

c++ - 为什么在使用线程池时对 boost::async 的嵌套调用会阻塞?