gcc compile error: ::div has not been declared

Started by
3 comments, last by Bregma 13 years, 2 months ago
so.... compiling this with g++ 4.2.3 on ubuntu...
#include <string>

.... i get:

In file included from /usr/include/c++/4.2/bits/stl_algobase.h:68,
                 from /usr/include/c++/4.2/bits/char_traits.h:46,
                 from /usr/include/c++/4.2/string:47,
                 from test.cpp:2:
/usr/include/c++/4.2/cstdlib:117: error: ‘::div’ has not been declared
/usr/include/c++/4.2/cstdlib:122: error: ‘::ldiv’ has not been declared
/usr/include/c++/4.2/cstdlib: In function ‘ldiv_t std::div(long int, long int)’:
/usr/include/c++/4.2/cstdlib:146: error: ‘ldiv’ was not declared in this scope
/usr/include/c++/4.2/cstdlib: At global scope:
/usr/include/c++/4.2/cstdlib:164: error: ‘::lldiv_t’ has not been declared
/usr/include/c++/4.2/cstdlib:170: error: ‘::_Exit’ has not been declared
/usr/include/c++/4.2/cstdlib:177: error: ‘::llabs’ has not been declared
/usr/include/c++/4.2/cstdlib:179: error: ‘lldiv_t’ does not name a type
/usr/include/c++/4.2/cstdlib:183: error: ‘::lldiv’ has not been declared
/usr/include/c++/4.2/cstdlib:194: error: ‘::atoll’ has not been declared
/usr/include/c++/4.2/cstdlib:195: error: ‘::strtoll’ has not been declared
/usr/include/c++/4.2/cstdlib:196: error: ‘::strtoull’ has not been declared
/usr/include/c++/4.2/cstdlib:198: error: ‘::strtof’ has not been declared
/usr/include/c++/4.2/cstdlib:199: error: ‘::strtold’ has not been declared
/usr/include/c++/4.2/cstdlib:206: error: ‘__gnu_cxx::lldiv_t’ has not been declared
/usr/include/c++/4.2/cstdlib:208: error: ‘__gnu_cxx::_Exit’ has not been declared
/usr/include/c++/4.2/cstdlib:211: error: ‘__gnu_cxx::llabs’ has not been declared
/usr/include/c++/4.2/cstdlib:212: error: ‘__gnu_cxx::div’ has not been declared
/usr/include/c++/4.2/cstdlib:213: error: ‘__gnu_cxx::lldiv’ has not been declared
/usr/include/c++/4.2/cstdlib:215: error: ‘__gnu_cxx::atoll’ has not been declared
/usr/include/c++/4.2/cstdlib:216: error: ‘__gnu_cxx::strtof’ has not been declared
/usr/include/c++/4.2/cstdlib:217: error: ‘__gnu_cxx::strtoll’ has not been declared
/usr/include/c++/4.2/cstdlib:218: error: ‘__gnu_cxx::strtoull’ has not been declared
/usr/include/c++/4.2/cstdlib:219: error: ‘__gnu_cxx::strtold’ has not been declared


Uhm, I'm guessing i've got to define something?
Advertisement
Quote:Original post by RobTheBloke
Uhm, I'm guessing i've got to define something?

You shouldn't have to. It sounds more like a munged installation.

It looks like what's happening is that something is preventing the definitions of things like ::ldiv in /usr/include/stddef.h. The string header pulls in char_traits.h, which pulls in stl_algobase.h, which pulls in cstdlib, which pulls in stdlib.h so it can hoist various symbols from the :: namespace into the std::namespace. Unfortunately, those required symbols are not getting defined through stdlib.h for some reason.

In your test.cpp, did you #define anything odd or did you (on line 1) #include anything that might define anything odd?

Try keeping the preprocessed source file (g++ -save-temps ....) and seeing what is going in stdlib.h.

Stephen M. Webb
Professional Free Software Developer

Problem solved. I was porting some Win32 code and had included wine into my include search paths. That then gave priority to the stdlib.h provided with wine.

Problem solved. I was porting some Win32 code and had included wine into my include search paths. That then gave priority to the stdlib.h provided with wine.



I've encountered the same problem but couldn't understand your solution - can you please explain what you did more broadly?

Thanx

I've encountered the same problem but couldn't understand your solution - can you please explain what you did more broadly?

His problem was he added additional directories to the list of search paths the compiler uses to find header files, and those additional directories contained header files with the same name as standard system header files. Because of the way in which those directories were added, the non-standard header files were being used in place of the standard header files.

Specifically, he probably used the [font="Times New Roman"]-I gcc command line switch in his build mechanism to add a directory path (folder name) that he should not have.

The solution is to check what [font="Times New Roman"]-I arguments appear on the compile command line, and remove the inappropriate ones. How to do this will depend on what build machinery you are using. Give is some more information on what you are doing and we can give you more information on how to specifically solve your problem.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement