开发者

Using map functions ubuntu

I'm trying to compile the following code in 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;

Using this command

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

And i get this error

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

Here is a locate for map.h

1234@(none):/usr/local/src/testing$ locate 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

Additionally i do have other studd in there for mysql, which i will be using, but main is just returning 0;


If you didn't totally mess up your compiler setup, you shouldn't need to pass that many options. You should be fine to remove -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

Also, since you tweaked your include paths you were able to see an implementation file unordered_map.h which should not be included directly. Instead include

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

or

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

In general, the "standard library" headers for C++ do not have a .h in their names. The C library headers have it (e.g. math.h), but you are provided an additional version with their declarations wrapped properly in the standard namespace. These headers start with c, e.g. cmath.


Either use std::unordered_map and the standard header <unordered_map> or use std::map and the standard header <map>. Don’t mix the two.


You should never have to -I into the g++ bits directory, but just the include directory directly. This leads me to believe you're using a library that's not compatible with your compiler.

Another option is that code prior to the include of map is broken and has mismatched { } for example.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜