Solved

DJGPP

Posted on 2004-09-21
16
577 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:npuleio
  • 5
  • 5
  • 2
  • +2
16 Comments
 
LVL 11

Expert Comment

by:avizit
ID: 12120263
did you try putting

using namespace std;    

just below the #include headers

or when you declare string try as

std::string test;

0
 

Author Comment

by:npuleio
ID: 12120418
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
 
LVL 11

Expert Comment

by:avizit
ID: 12120434
try
#include <string>

instead of

#include <string.h>
0
 
LVL 11

Expert Comment

by:avizit
ID: 12120448
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
 

Author Comment

by:npuleio
ID: 12120506
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
 
LVL 11

Expert Comment

by:avizit
ID: 12120546
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
 

Author Comment

by:npuleio
ID: 12120650
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12120689
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:avizit
ID: 12120716
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
 

Author Comment

by:npuleio
ID: 12120723
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
 

Accepted Solution

by:
axsaxs earned 125 total points
ID: 12120977

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

0
 

Expert Comment

by:axsaxs
ID: 12121173

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

Ciao,
Alessio
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12121194
>>>> 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
 

Author Comment

by:npuleio
ID: 12121677
Grazie Alessio

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

Thanks all!
Ciao, Luigi
0
 
LVL 30

Expert Comment

by:Axter
ID: 12141511
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
 
LVL 30

Expert Comment

by:Axter
ID: 12141521
FYI:
I notice you have a very poor grading history.
B C B C B B B
Please read the grading guide lines.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now