DJGPP

Hello everyone....

Had to install last version of DJGPP, but when I compile code where I use string variables it says string undeclared and I have included the string.h....
is that maybe related to the bug of the compiler I see that says: "nonexistent directory: C:\DJGPP\DJGPP\INCLUDE" and what I could do?

Thanks.
Ciao,
Luigi
npuleioAsked:
Who is Participating?
 
axsaxsConnect With a Mentor Commented:

Try minGW - http://www.mingw.org/

0
 
avizitCommented:
did you try putting

using namespace std;    

just below the #include headers

or when you declare string try as

std::string test;

0
 
npuleioAuthor Commented:
On this PC I tried to compile a stupid hello world just to see if it compiles:

#include <string.h>
  using namespace std;

int main() {

  string miavariabile;

  miavariabile="Hello world!";

  printf("%s\n", miavariabile);

  return 0;
}

but it returns this:

C:\Progetti\XML\Prove>gcc hello.cpp -o hello.exe
hello.cpp: In function `int main()':
hello.cpp:6: error: `string' undeclared (first use this function)
hello.cpp:6: error: (Each undeclared identifier is reported only once for each f
unction it appears in.)
hello.cpp:6: error: expected `;' before "miavariabile"
hello.cpp:8: error: `miavariabile' undeclared (first use this function)
hello.cpp:10: error: `printf' undeclared (first use this function)
hello.cpp:13:2: warning: no newline at end of file

And I have also the LFN set as Y in the djgpp.env. I guess the compiler is bugged or something...could that be?

Thanks.
Ciao, Luigi
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
avizitCommented:
try
#include <string>

instead of

#include <string.h>
0
 
avizitCommented:
string is defined in  <string> and not the c-style header file <string.h>

also i am not sure but i think you should print strings with "cout" and not printf

so guess you should also change

 printf("%s\n", miavariabile);

to

cout<<miavariabile;

0
 
npuleioAuthor Commented:
If I modify the stupid hello world as this:

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#include <iostream>
#include <string>

using namespace std;

int main() {

  string miavariabile;

  miavariabile="Hello world!";

  cout<<miavariabile;

  return 0;
}

I get this:

C:\Progetti\XML\Prove>gcc hello.cpp -o hello.exe
hello.cpp:19:2: warning: no newline at end of file
c:/djgpp/tmp/cc2oZkQK.o(.text+0xd):hello.cpp: undefined reference to `std::basic
_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x60):hello.cpp: undefined reference to `std::basi
c_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsign
ed long) const'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x9d):hello.cpp: undefined reference to `std::basi
c_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsign
ed long) const'
c:/djgpp/tmp/cc2oZkQK.o(.text+0xc8):hello.cpp: undefined reference to `std::basi
c_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsign
ed long) const'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x135):hello.cpp: undefined reference to `std::bas
ic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x149):hello.cpp: undefined reference to `std::bas
ic_string<char, std::char_traits<char>, std::allocator<char> >::operator=(char c
onst*)'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x158):hello.cpp: undefined reference to `std::cou
t'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x15d):hello.cpp: undefined reference to `std::bas
ic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_trai
ts<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char>
 >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > cons
t&)'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x16c):hello.cpp: undefined reference to `std::bas
ic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'

c:/djgpp/tmp/cc2oZkQK.o(.text+0x18a):hello.cpp: undefined reference to `std::bas
ic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'

c:/djgpp/tmp/cc2oZkQK.o(.text+0x1c6):hello.cpp: undefined reference to `std::ios
_base::Init::Init()'
c:/djgpp/tmp/cc2oZkQK.o(.text+0x1e5):hello.cpp: undefined reference to `std::ios
_base::Init::~Init()'
c:/djgpp/tmp/cc2oZkQK.o(.eh_frame+0x12):hello.cpp: undefined reference to `___gx
x_personality_v0'
collect2: ld returned 1 exit status

mmmm guess it's so strange that doesn't see the string or even iostream...another suggest?
0
 
avizitCommented:
I googled a bit and the following might be related to your problem

http://www.delorie.com/djgpp/v2faq/faq8_11.html

--
so try compiling with option -O2  

pasting parts from the above link

Q: I can't compile a program which uses the String class: the linker complains about undefined functions!
A: Some C++ functions are declared inline and defined on header files. (One example of this is the string constructor of the GNU String class.) However, GCC won't inline them unless you compile with optimizations enabled, so it tries to find the compiled version of the functions in the library. Workaround: compile with -O2.

0
 
npuleioAuthor Commented:
Hummmm.....nada, even using that -O2's option it works...

maybe DJGPP's obsolete?.... but that's ANSI C++...it should work! I'm gettin mad hehehhe just got a cup of coffee to calm down hahaha

Oh well another suggest again or better trash the PC out the window?


Thanks
Ciao,
Luigi
0
 
itsmeandnobodyelseCommented:
Try to remove the includes below. You definitely don't need them for the prog above. Also, if mixing old headers with STL header files, always include  STL header files first (that's because STL knows about old header files but not vice versa).

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

Regards, Alex


0
 
avizitCommented:
actually in c++ programs if you want to use C headers itspreferable to include them as

#include <cstdio>
#include <cstdlib>

etc etc ...

on a personal note . I prefer devcpp  - http://www.bloodshed.net/devcpp.html
0
 
npuleioAuthor Commented:
Looks like it doesn't affect the compilation...it shows the same messages as above...

Oh darn it...looks like I'll have to get another cup of coffee....hehe

maybe djgpp's obsolete?... the fact is as far as I know I don't think there's another ANSI C++ compiler as djgpp to try...or yes?

Ciao,
Luigi
0
 
axsaxsCommented:

Also, with DJGPP, try to compile with gxx instead of gcc.

Ciao,
Alessio
0
 
itsmeandnobodyelseCommented:
>>>> nonexistent directory: C:\DJGPP\DJGPP\INCLUDE

Maybe that's not a 'compiler bug' but a wrong project configuration. Check your configuration files and/or your makefile for that definition and correct it.

Regards, Alex
0
 
npuleioAuthor Commented:
Grazie Alessio

With minGW it compiled ok so that works here now :-)
No more coffee finally hehe more relax

Thanks all!
Ciao, Luigi
0
 
AxterCommented:
npuleio,
Please delete the following question:

http:Q_21143498.html

You can delete it without Commnunity Support helping you if you delete it before another expert post on a comment on it.
That's why I'm post this message in this question instead of above question.

0
 
AxterCommented:
FYI:
I notice you have a very poor grading history.
B C B C B B B
Please read the grading guide lines.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.