Hi, I have three c++ files: main.cpp, and querystring.{h,cpp} querystring.h contains the definition for the QueryString class and querystring.cpp contains the implementation. querystring.cpp and main.cpp both have the statement #include "querystring.h" Now when I run the compiler, I get a weird error- $ g++ main.cpp querystring.cpp -o out /tmp/ccxJ7C28.o: In function `main': main.cpp:(.text+0x3e): undefined reference to `QueryString::QueryString()' collect2: ld returned 1 exit status How am I supposed to compile the program? i.e. in general a multifile program having .hs and .cpps -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com VPS Hosting: http://www.itech7.com/a/vps
On Sunday 14 November 2010 18:59:28 Nilesh Govindarajan wrote:
How am I supposed to compile the program? i.e. in general a multifile program having .hs and .cpps
I should work the way you did. I guess you have an error in your source code. The oder method would be: g++ -c main.cpp g++ -c querystring.cpp g++ -o out main.o querystring.o Bye...Frank
On 14/11/10 18:24, Frank Thieme wrote:
On Sunday 14 November 2010 18:59:28 Nilesh Govindarajan wrote:
How am I supposed to compile the program? i.e. in general a multifile program having .hs and .cpps
I should work the way you did. I guess you have an error in your source code.
The oder method would be:
g++ -c main.cpp g++ -c querystring.cpp g++ -o out main.o querystring.o
Order is important. I think he'd have more luck with the last line changed to g++ -o out querystring.o main.o /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
On Sunday 14 November 2010 19:27:01 Magnus Therning wrote:
Order is important. I think he'd have more luck with the last line changed to
g++ -o out querystring.o main.o
Is it? I must have slipped my mind... I usually use cmake or some other makefile, so I don't have to type these lines myself. Bye...Frank
On 14/11/10 18:34, Frank Thieme wrote:
On Sunday 14 November 2010 19:27:01 Magnus Therning wrote:
Order is important. I think he'd have more luck with the last line changed to
g++ -o out querystring.o main.o
Is it? I must have slipped my mind...
Yes, in the link step it is, since it's single pass.
I usually use cmake or some other makefile, so I don't have to type these lines myself.
Same here, except for when I add support for some language to a build tool like cmake :-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
On 14/11/10 17:59, Nilesh Govindarajan wrote:
Hi, I have three c++ files: main.cpp, and querystring.{h,cpp}
querystring.h contains the definition for the QueryString class and querystring.cpp contains the implementation.
querystring.cpp and main.cpp both have the statement #include "querystring.h"
Now when I run the compiler, I get a weird error-
$ g++ main.cpp querystring.cpp -o out /tmp/ccxJ7C28.o: In function `main': main.cpp:(.text+0x3e): undefined reference to `QueryString::QueryString()' collect2: ld returned 1 exit status
How am I supposed to compile the program? i.e. in general a multifile program having .hs and .cpps
This isn't really the right forum to ask a question like this. My guess would be the order of the files on the command line, try $ g++ querystring.cpp main.cpp -o out /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
On 11/14/2010 11:29 PM, Nilesh Govindarajan wrote:
Hi, I have three c++ files: main.cpp, and querystring.{h,cpp}
Guys, thanks for your suggestion, but the problem turned out to be inline constructor. I don't know why that doesn't work (it's as per ANSI though). -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com VPS Hosting: http://www.itech7.com/a/vps
On Mon, Nov 15, 2010 at 13:00, Nilesh Govindarajan <lists@itech7.com> wrote:
On 11/14/2010 11:29 PM, Nilesh Govindarajan wrote:
Hi, I have three c++ files: main.cpp, and querystring.{h,cpp}
Guys, thanks for your suggestion, but the problem turned out to be inline constructor. I don't know why that doesn't work (it's as per ANSI though).
I'm sure actual examples would have helped here :-) /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
On 11/15/2010 10:17 PM, Magnus Therning wrote:
On Mon, Nov 15, 2010 at 13:00, Nilesh Govindarajan<lists@itech7.com> wrote:
On 11/14/2010 11:29 PM, Nilesh Govindarajan wrote:
Hi, I have three c++ files: main.cpp, and querystring.{h,cpp}
Guys, thanks for your suggestion, but the problem turned out to be inline constructor. I don't know why that doesn't work (it's as per ANSI though).
I'm sure actual examples would have helped here :-)
/M
So here it is: class QueryString { private: const string __qstr; public: QueryString() { throw Exception("Invalid constructor"); // defined in Exception.h } QueryString(const char* s) : __qstr(s) {} QueryString(const string& s): __qstr(s) {} http_map* parse(); }; PS: The default constructor is pretty dumb logic, I'll be changing that :) This doesn't compile on my box, saying `undefined reference to QueryString::QueryString()' or any other constructor. It doesn't matter if I define it inside (therefore implicitly inline as per ANSI) or outside using the inline keyword, it still won't compile (at least on my arch64). -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com VPS Hosting: http://www.itech7.com/a/vps
I'm absolutely stunned now when the same program (inlined constructors) compiles now, without ANY change in the gcc flags, etc. Probably the CPU had got heated up that day lol. -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com VPS Hosting: http://www.itech7.com/a/vps
On 11/16/2010 08:54 PM, Nilesh Govindarajan wrote:
I'm absolutely stunned now when the same program (inlined constructors) compiles now, without ANY change in the gcc flags, etc.
Probably the CPU had got heated up that day lol.
The problem has come back again. Well anyways, let's close this thread, the problem is oscillating between success & failure. I'll google it out myself (if possible). Loading it dynamically (dlfcn.h) solves the issue for the time being. -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com VPS Hosting: http://www.itech7.com/a/vps
On Tue, Nov 16, 2010 at 16:10, Nilesh Govindarajan <lists@itech7.com> wrote:
On 11/16/2010 08:54 PM, Nilesh Govindarajan wrote:
I'm absolutely stunned now when the same program (inlined constructors) compiles now, without ANY change in the gcc flags, etc.
Probably the CPU had got heated up that day lol.
The problem has come back again. Well anyways, let's close this thread, the problem is oscillating between success & failure. I'll google it out myself (if possible).
Loading it dynamically (dlfcn.h) solves the issue for the time being.
Paste a complete (all required files included), minimal example on gist.github.com or something, that might make it easier to spot the problem. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
not that I mind solving a nit picky c++ puzzle and tracking down a code bug....but.. isn't this completely off base/topic for this list? -- @csgeek On Tue, Nov 16, 2010 at 11:08 AM, Magnus Therning <magnus@therning.org>wrote:
On Tue, Nov 16, 2010 at 16:10, Nilesh Govindarajan <lists@itech7.com> wrote:
On 11/16/2010 08:54 PM, Nilesh Govindarajan wrote:
I'm absolutely stunned now when the same program (inlined constructors) compiles now, without ANY change in the gcc flags, etc.
Probably the CPU had got heated up that day lol.
The problem has come back again. Well anyways, let's close this thread, the problem is oscillating between success & failure. I'll google it out myself (if possible).
Loading it dynamically (dlfcn.h) solves the issue for the time being.
Paste a complete (all required files included), minimal example on gist.github.com or something, that might make it easier to spot the problem.
/M
-- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe
-- csgeek
On 11/17/2010 08:02 PM, csgeek wrote:
not that I mind solving a nit picky c++ puzzle and tracking down a code bug....but.. isn't this completely off base/topic for this list?
-- @csgeek
I don't think so, as per the problem, I follow ANSI C++ and g++ won't compile the thing. I thought this was something specific to g++ on arch so it may require some extra flags, like that, hence I posted it here. -- Regards, Nilesh Govindarajan Facebook: http://www.facebook.com/nilesh.gr Twitter: http://twitter.com/nileshgr Website: http://www.itech7.com VPS Hosting: http://www.itech7.com/a/vps
participants (4)
-
csgeek
-
Frank Thieme
-
Magnus Therning
-
Nilesh Govindarajan