ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
class outlinepiece {
public:
outlinepiece( int nodeNUM, string node1, string nodes2);
string givenode();
string givesubnode();
string givesupernode();
int givenumnode();
};
#endif // OUTLINEPIECE_CLASS
I used:
gcc -o testerprog testerprog.c outlinepiece.c
I get so many errors like:
testerprog.c:2:20: iostream: No such file or directory
testerprog.c:3:18: string: No such file or directory
In file included from testerprog.c:4:
outlinepiece.h:4: parse error before "outlinepiece"
outlinepiece.h:5: syntax error before '{' token
outlinepiece.h:8: warning: data definition has no type or storage class
outlinepiece.h:9: parse error before "givesubnode"
outlinepiece.h:9: warning: data definition has no type or storage class
outlinepiece.h:10: parse error before "givesupernode"
outlinepiece.h:10: warning: data definition has no type or storage class
outlinepiece.h:12: parse error before '}' token
testerprog.c:6: parse error before "namespace"
testerprog.c:6: warning: data definition has no type or storage class
testerprog.c:9: syntax error before '{' token
testerprog.c:11: warning: initialization makes integer from pointer without a cast
testerprog.c:11: warning: data definition has no type or storage class
testerprog.c:13: parse error before "tester1"
testerprog.c:13: warning: parameter names (without types) in function declaration
testerprog.c:13: warning: data definition has no type or storage class
testerprog.c:14: parse error before '<<' token
outlinepiece.c:2:18: string: No such file or directory
In file included from outlinepiece.c:3:
outlinepiece.h:4: parse error before "outlinepiece"
outlinepiece.h:5: syntax error before '{' token
outlinepiece.h:8: warning: data definition has no type or storage class
outlinepiece.h:9: parse error before "givesubnode"
outlinepiece.h:9: warning: data definition has no type or storage class
outlinepiece.h:10: parse error before "givesupernode"
outlinepiece.h:10: warning: data definition has no type or storage class
outlinepiece.h:12: parse error before '}' token
outlinepiece.c:5: parse error before "outlinepiece"
outlinepiece.c:14: parse error before ':' token
Hey I just started with C++ the other day. I read the documentation for gcc, and it seems to suggest all along that it will detect files in C++ rather than in plain C and compile them accordingly. Unfortunately this didn't work for me. To cut a long story short, replace 'gcc' in your command with 'g++' to force it to compile for C++.
An awful lot of the times, subsequent errors are caused by the very first error.
Examine the first error listed and tell me what happened.
This is a case of me not giving you the fish but teaching you how to fish. You'll get no production if you have to wait for someone else to debug your problems.
I compiled it with: g++ -o testerprog testerprog.cpp
I get the following result:
[root@localhost bin]# g++ -o testerprog testerprog.cpp
testerprog.cpp:8: syntax error before `{' token
testerprog.cpp:12: `strnode' was not declared in this scope
testerprog.cpp:13: syntax error before `<<' token
ok, on the first two, I have no clue what is going on. on the third, I think it might be a namespace issue?
any help is appreciated, it has come a long way fast, thanks to all (except Dave with that fish remark), I've read a lot about C++, just squat about compilers
so i fixed that () and the strnodes error; the << error went away on its own
now the files look like:
//testerprog.cpp
#include <iostream>
#include <string>
#include "outlinepiece.h"
Originally posted by ttucker
[root@localhost bin]# g++ -o testerprog testerprog.cpp
/usr/bin/ld: cannot open crt1.o: No such file or directory
collect2: ld returned 1 exit status
No idea what is going on now, none.
ttucker
I'm assuming the program is having trouble locating what it needs to link which makes sense, since you have 3 source files and are only compiling one, in which case you need to tell it to compile and NOT link sinc eyou have not compiled the other two source files to link with yet. Try adding -c to the command line, this tell the compiler to simply compile and not link.
You should compile the two source files that do not define the funciton main() using -c then try compiling the one with main not using the -c option. If your paths are set up right, the compiler then should compile the code, in the initial fiel and link it to the code in the other 2 files correctly.
You might be better off looking into an IDE, I'm guessing you are used to using an IDE with project files to compile your apps, and not used to manually compiling each source file and linking them yourself.
I have been out of programming for far too long to reccomend an IDE to you however.
hopefully someone else here can steer you to the direction of a half way decent Integrated Development Environemnt for G++.
Also it might be strings and not string you need to include, it has been a while but I seem to recall it having an s.
Last edited by WhiteChedda; 09-17-2004 at 08:11 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.