[opensuse] Linking problem with g++ [off topic]
Sorry to use this list for my problem, but I really need a quick answer I have defined a class into two files XP_class.h and XP_class.cpp and use the header XP_class.h into another file xml_parser.cpp to create an object in the main function. However, when compiling and linking all the files, I get the following error: g++ `xml2-config --cflags` xml_parser.cpp XP_class.cpp `xml2-config -- libs` -o xml_parser /tmp/ccX1d5Hj.o: In function `main': xml_parser.cpp:(.text+0x195): undefined reference to `XP::XP()' xml_parser.cpp:(.text+0x1a8): undefined reference to `XP::init_DOM(char const*)' xml_parser.cpp:(.text+0x1c2): undefined reference to `XP::~XP()' xml_parser.cpp:(.text+0x229): undefined reference to `XP::get_value(char const*)' xml_parser.cpp:(.text+0x2b7): undefined reference to `XP::~XP()' collect2: ld returned 1 exit status I know that it must be some simple mistake, but I was not been able to figure out what it is. I would appreciate your help. regards -- Bogdan Cristea -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Bogdan Cristea wrote:
Sorry to use this list for my problem, but I really need a quick answer
I have defined a class into two files XP_class.h and XP_class.cpp and use the header XP_class.h into another file xml_parser.cpp to create an object in the main function. However, when compiling and linking all the files, I get the following error:
g++ `xml2-config --cflags` xml_parser.cpp XP_class.cpp `xml2-config -- libs` -o xml_parser /tmp/ccX1d5Hj.o: In function `main': xml_parser.cpp:(.text+0x195): undefined reference to `XP::XP()' xml_parser.cpp:(.text+0x1a8): undefined reference to `XP::init_DOM(char const*)' xml_parser.cpp:(.text+0x1c2): undefined reference to `XP::~XP()' xml_parser.cpp:(.text+0x229): undefined reference to `XP::get_value(char const*)' xml_parser.cpp:(.text+0x2b7): undefined reference to `XP::~XP()' collect2: ld returned 1 exit status
I know that it must be some simple mistake, but I was not been able to figure out what it is. I would appreciate your help.
regards
Maybe opensuse-programming would be a more appropriate place to ask this question ...... and it might be a good idea to give a bit more info about the source code to that list ... Off the top of the head this would suggest private or protected destructor/constructor and function definition issue, but that is a really wild stab in the dark, and someone who's C++ is not as rusty as mine is could give a more authoritative answer than I can, with more info. - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFH+6JfasN0sSnLmgIRAr+8AJ4j3BVA8XIprubD42Rk+lFG51iwHQCeMumM oSabFAx44/hAjei/UUPYZlk= =gU5H -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Bogdan Cristea wrote:
Sorry to use this list for my problem, but I really need a quick answer
I have defined a class into two files XP_class.h and XP_class.cpp and use the header XP_class.h into another file xml_parser.cpp to create an object in the main function. However, when compiling and linking all the files, I get the following error:
g++ `xml2-config --cflags` xml_parser.cpp XP_class.cpp `xml2-config -- libs` -o xml_parser /tmp/ccX1d5Hj.o: In function `main': xml_parser.cpp:(.text+0x195): undefined reference to `XP::XP()' xml_parser.cpp:(.text+0x1a8): undefined reference to `XP::init_DOM(char const*)' xml_parser.cpp:(.text+0x1c2): undefined reference to `XP::~XP()' xml_parser.cpp:(.text+0x229): undefined reference to `XP::get_value(char const*)' xml_parser.cpp:(.text+0x2b7): undefined reference to `XP::~XP()' collect2: ld returned 1 exit status
I know that it must be some simple mistake, but I was not been able to figure out what it is. I would appreciate your help.
Look for an error which is syntactically legal, but semantically wrong (say like, a forgotten } character), which would make your XP object definition be inside another function. C and C++ are notorious for indicating certain types of errors after the line on which the actual mistake is located.
regards
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Thank you for your answers. I have used some inline functions, but it
seems that the compiler does not support inline functions implemented
elsewhere than in the header file.
On Tue, Apr 8, 2008 at 7:53 PM, Sam Clemens
Bogdan Cristea wrote:
Sorry to use this list for my problem, but I really need a quick answer
I have defined a class into two files XP_class.h and XP_class.cpp and use the header XP_class.h into another file xml_parser.cpp to create an object in the main function. However, when compiling and linking all the files, I get the following error:
g++ `xml2-config --cflags` xml_parser.cpp XP_class.cpp `xml2-config -- libs` -o xml_parser /tmp/ccX1d5Hj.o: In function `main': xml_parser.cpp:(.text+0x195): undefined reference to `XP::XP()' xml_parser.cpp:(.text+0x1a8): undefined reference to `XP::init_DOM(char const*)' xml_parser.cpp:(.text+0x1c2): undefined reference to `XP::~XP()' xml_parser.cpp:(.text+0x229): undefined reference to `XP::get_value(char const*)' xml_parser.cpp:(.text+0x2b7): undefined reference to `XP::~XP()' collect2: ld returned 1 exit status
I know that it must be some simple mistake, but I was not been able to figure out what it is. I would appreciate your help.
Look for an error which is syntactically legal, but semantically wrong (say like, a forgotten } character), which would make your XP object definition be inside another function.
C and C++ are notorious for indicating certain types of errors after the line on which the actual mistake is located.
regards
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-- Bogdan Cristea -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Wed, 9 Apr 2008 09:06:53 +0300, Bogdan Cristea wrote:
Thank you for your answers. I have used some inline functions, but it seems that the compiler does not support inline functions implemented elsewhere than in the header file.
Yes, in order to inline a function, the compiler has to see the complete implementation. The C++ standard offers the 'export' keyword, but few if any C++ compilers implement that. But the warnings you see come from the linker, not the compiler (though g++ calls the linker). Being that ld is a one pass linker like most Unix linkers, make sure the objects defining a function come before those objects using them. BTW, to see what objects/libraries export and import, use nm and for C++ code use the --demangle option of nm to get the symbols demangled and thus better readable. Philipp -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (4)
-
Bogdan Cristea
-
G T Smith
-
Philipp Thomas
-
Sam Clemens