Solved

Compiler errors

Posted on 2002-07-24
28
884 Views
Last Modified: 2012-06-27
I am using Sun Workshop 5 C++ compiler.  I am trying to compile a program on a Solaris 8 platform and get the following indications:
billthecat:[/export/home/cary/DASS/Scheduler]make
CC -c -g -mt -DILDINGRES -DRW_USE_OBJECTSTORE -DDEBUG -I../Assembly -I/opt/local/rogue -I/usr/ilog/sched52/include -I/usr/ilog/solver52/include -I/usr/ilog/dblink30/include   -I/usr/ilog/views241/include  -I/opt/ODI/OS5.0/sunpro/include -I/opt/WS5/SUNWspro/SC5.0/include/CC -I. -I/usr/ilog/concert12/include SchDbsched_os.cc
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 14: Error: Type name expected instead of "namespace".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 22: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 23: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 24: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 25: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 26: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 27: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 28: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 29: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 30: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 31: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 32: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 33: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 34: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 35: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 36: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 37: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 38: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 39: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 40: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 41: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 42: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/string.h", line 43: Error: Type name expected instead of "using".
"/opt/WS5/SUNWspro/SC5.0/include/CC/stddef.h", line 14: Error: Type name expected instead of "namespace".
"/opt/WS5/SUNWspro/SC5.0/include/CC/stddef.h", line 17: Error: Type name expected instead of "using".
Compilation aborted, too many Error messages.
*** Error code 1
make: Fatal error: Command failed for target `SchDbsched_os.o'

Any ideas on what is causing this?
0
Comment
Question by:carydb
  • 13
  • 7
  • 3
  • +4
28 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 25 total points
ID: 7175291
It seems that you are using the C compier instead of the C++ compier - try 'cxx' instead of 'cc'.
0
 

Author Comment

by:carydb
ID: 7175455
Hmmm. Am using the C++ compiler in the makefile.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175524
>>Hmmm. Am using the C++ compiler in the makefile.

If your file name is of C type, then your compiler will treat the code like a C file.

Rename your file to a c++ type file like SchDbsched_os.cpp
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175535
FYI:
That is what jkr was refferring too by "try 'cxx' instead of 'cc'"
0
 
LVL 86

Expert Comment

by:jkr
ID: 7175543
>>That is what jkr was refferring too by "try 'cxx' instead of 'cc'"

No, - '.cc' is a legit extension for C++ files, as .cxx and .cpp. I was referring to the compiler.

BTW: 'string.h' indicates that you are using deprecated headers...
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175597
>>No, - '.cc' is a legit extension for C++ files, as .cxx
>>and .cpp. I was referring to the compiler.

Hmm... I thought *.cc was a C extension.  Is this documented any where, or is it just common practice?
0
 
LVL 86

Expert Comment

by:jkr
ID: 7175627
>>Is this documented any where, or is it just common practice?

'man gcc' documents that as follows:

       Suffixes of source file names indicate  the  language  and
       kind of processing to be done:

       .c    C source; preprocess, compile, assemble
       .C    C++ source; preprocess, compile, assemble
       .cc   C++ source; preprocess, compile, assemble
       .cxx  C++ source; preprocess, compile, assemble
       .m    Objective-C source; preprocess, compile, assemble
       .i    preprocessed C; compile, assemble
       .ii   preprocessed C++; compile, assemble
       .s    Assembler source; assemble
       .S    Assembler source; preprocess, assemble
       .h    Preprocessor file; not usually named on command line
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175665
Could it be that the "Sun Workshop 5 C++ compiler" doen't use the same extension type as the GNU compiler?

carydb,
I would still change the extension name, just to see what would happen.  Can't hurt to try.

Another thing to look at is do you have "using namespace std" in your SchDbsched_os.cc file?

If you have "using namespace std" in your code and you're mixing depreciated headers with new C++ extension-less headers, this can sometimes cause compiler errors.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175676
Continue.....

The "using namespace std" problem is espcially true when you have it before the header includes.
Example:

using namespace std;//Wrong location for this
#include <string>
#include <iostream>
#include <string.h>

I don't recommend that you use "using namespace std", but if you do decide to use it, place it after the include headers, like the following example:

#include <string>
#include <iostream>
#include <string.h>

using namespace std;

0
 
LVL 30

Expert Comment

by:Axter
ID: 7175678
Also, make sure that the depriciated files are listed last like in the above example.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7175679
Maybe I'm missing something here, but what would you need <string.h> for if you have std::string's (<string>)?
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175702
>>Maybe I'm missing something here, but what would you
>>need <string.h> for if you have std::string's (<string>)?

The string.h header file includes the C string.h header.
This header declares things like strcpy, strstr, strcmp, strcat, etc....

According to the current C++ standard, you're suppose to use <cstring> instead of <string.h> for new code.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7175711
I know what it defines, but what would you need it for if you already included <string>?
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175748
>>I know what it defines, but what would you need it for
>>if you already included <string>?

strcpy, strstr, strcmp, strcat, etc...., are NOT declared in the <string> header.

I know, I know, ... when you use VC++, and you include <string>, it lets you compile strcpy and associated functions.

Well that because <cstring> gets included indirectly.
See following path

<string> -> <istream> -> <ostream> -> <ios> -> <streambuf> -> <xlocnum> -> <xiosbase> ->  
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 30

Expert Comment

by:Axter
ID: 7175761
Opps!!! I clicked the submit button before I was done.

<string> -> <istream> -> <ostream> -> <ios> -> <streambuf> -> <xlocnum> -> <xiosbase> ->  <xlocale> -> <cstring> -> <string.h>

So at the end of the day, <string> is just using <string.h> to get the str??? function declarations.
This applies to VC++, and other compilers may have different implementation.  
Which means to say, that using <string> to get the declaration for str??? functions may not work on other compilers, thereby making your code non-portable.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7175765
I know, but what would you need strcpy, strstr, strcmp, strcat, etc, if you already have std::strings????
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175787
There are lots of reasons for needing the old C style string functions.

Just to name three:

1.  If you're using legacy code
2.  If you have to inteface with a C style function
3.  You don't want the overhead of std::string (for real time code or code with limited space)
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7175817
But you already included <string> so 1 and 3 are already discarded. For 2.): use the c_str()-function... Still can't see any use for <string.h> if you already have std::string's.

I do, however, see the need for c-style strings in those two examples you named.
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175864
>>2.): use the c_str()-function

This is dangerous to do with SOME C style code.  And in general should not be done.

The problem with trying to use std::string is that what c_str() returns, should not be stored, or attempted to use again.
For example:
#include <string>
#include <iostream>

int main(int argc, char* argv[])
{
     std::string data = "Hello World";
     const char* ptr = data.c_str();

     std::cout << ptr << std::endl; //So far so good

     for (int i = 0;i < 1000;++i) data += data;
     data = "This is a test to see if the pointer is still valid";

     std::cout << ptr << std::endl; //Ops!!!

     system("pause");
     return 0;
}

With the above code, at best you'll get garbage printed out to your screen, and at worse it'll crash.

If you use a C style function that expects to hold on to the pointer, and keep it for continual use, this will be a problem if you pass it a pointer via c_str().


Now, you're probalby thinking that you can still make it work by initializing the size of your std::string object to the maximum size you think you'll need, and then pass it the pointer via c_str().

Will even with that, you can still run into problems.
Check out the following code:

int main(int argc, char* argv[])
{
     std::string data1 = "Hello World";
     std::string data2;
     data2.resize(200);
     data2 = data1;
     const char* ptr = data2.c_str();

     std::cout << ptr << std::endl; //So far so good

     data2 =  "Goodbye";

     std::cout << ptr << std::endl; //Ops!!!

     system("pause");
     return 0;
}

On VC++ 6.0, the above code will print "Hello World".
That's right.  You will not get a Goodbye.

In general, storing the pointer returned by c_str() is never a good idea, because the implementation is allowed to play around with the buffer pointed to by std::string, and it's not always easy to determine when this pointer is going to change.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7175879
The danger lies in the wrong usage of the c_str()-function. Equally dangerous is something like this:

void* p = malloc( 10 );
void* q = realloc( p, 100000 );

unsigned char c = *p;

may result in correct behaviour as well as rubbish or a crash.

To get back to the example: I don't understand why anyone would need to #include <string.h> after having #include'd <string>?
0
 
LVL 30

Expert Comment

by:Axter
ID: 7175903
>>To get back to the example: I don't understand why
>>anyone would need to #include <string.h> after having
>>#include'd <string>?

Remember, he's not useing VC++ compiler.  The Sun compiler may not be include <string.h> via <string>.  Which would mean you would not be able to use <string> to get your str??? function declarations.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7175927
I was talking about your post that started with "Continue....."
0
 
LVL 30

Expert Comment

by:Axter
ID: 7176233
>>I was talking about your post that started
>>with "Continue....."

Ohh... Got you.
It could be needed if someone is mixing C++ and C code together.
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7176243
At long last I got you too ;) You were using it as a hypothetical example rather than suggesting it... I feel guilty, a lot of webspace could have been saved.
0
 

Author Comment

by:carydb
ID: 7177865
Not using namespace std in the SchDbsched_os.cc file.

The following is what my compiler sees as far as suffixes.

Suffix 'a':           Object library
Suffix 'il':          Inline expansion file
Suffix 'o':           Object file
Suffix 'so':          Shared object
Suffix 's':           Assembler source
Suffix 'S':           Assembler source for cpp
Suffix 'c':           C++ source
Suffix 'cc':          C++ source
Suffix 'cpp':         C++ source
Suffix 'cxx':         C++ source
Suffix 'C':           C++ source
Suffix 'i':           C++ source after preprocessing
Suffix 'err':         ld error file

0
 
LVL 1

Expert Comment

by:JasonTheGreat
ID: 7180009
That is a tough one to track down; I have seen this before.  It usually means that the file that is included before <string> has a syntax error (most likely forgot the ; after a class definition).

Don't forget, you may have included a file before <string> that includes <string> as well.

If that doesn't jump out at you, run the code through the preprocessor only and then view and try to compile the resulting .i file.  You can do that by adding the -E option to and removing the -c option from your compile command and then redirect it to a file:

CC -E -g -mt -DILDINGRES -DRW_USE_OBJECTSTORE -DDEBUG -I../Assembly -I/opt/local/rogue -I/usr/ilog/sched52/include -I/usr/ilog/solver52/include -I/usr/ilog/dblink30/include   -I/usr/ilog/views241/include  -I/opt/ODI/OS5.0/sunpro/include -I/opt/WS5/SUNWspro/SC5.0/include/CC -I. -I/usr/ilog/concert12/include SchDbsched_os.cc > SchDbsched_os.i

The resulting .i file will show you exactly what the compiler sees when it generates the synxtax error.  If you still don't see it (this is a VERY verbose file!), run the file through a sed or perl script that comments out all the "#file" lines and then try to compile that file (you may have to name it .cxx or some other C++ extension).  The compiler will tell you exactly which line is causing the problem.

In conclusion, first check the file (or code) right before your #include <string> for a syntax error (most likely a missing ; after a class since it's expecting an identifier).  If that doesn't help you, run it through the preprocessor (with the -E) option; view and/or compile that file (minus the #file lines) to get more info.

Regards,

  --Jason

0
 
LVL 11

Expert Comment

by:griessh
ID: 7378443
Dear carydb

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split between

     "jkr and Axter"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7420044
Force accepted

** Mindphaser - Community Support Moderator **

Axter, there will be a separate question with points for your help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 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