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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The obvious error in your code is that your .hh file declares read and write inside namespace mapfile, while your mapfile.cc file defines them outside of any namespace.
But for all your non obvious errors, I have no clue. I'm not a fan of boost, so I don't use it much and I wouldn't know without research what is wrong with your use of it.
It helps to read the error message. You didn't tell the linker that you are linking to the boost library. It's not a compile time error, but a link time error (hence why there are no line numbers). You see all the 'undefined reference' messages; that should be a clue.
I believe you should add -lboost to your g++ line, but am not 100% sure what the exact library name is. Check the documentation.
Additionally, johnsfine pointed out something I overlooked completely.
Last edited by orgcandman; 12-28-2010 at 01:44 PM.
BTW, how is it possible to diagnose linker errors, especially when they don't have line numbers?
They don't give line numbers because your source code is syntactically correct. Whether your syntax accomplishes what you expect is a separate question. It's just like putting a puzzle together. Multiple pieces may fit together to form larger blocks, but if the larger blocks don't fit when put together, where is the problem? Is it the orientation of the large blocks or is it the individual pieces? If the individual pieces, which piece? (because they all appear to fit together correctly) There are multiple possibilities for the root cause of the error, and no way of identifying which is the "true" cause.
To debug, you look at the error messages and start at the top:
using namespace std;
. . .
void write(const map<string, string> & m, ofstream & file)
{
. . .
}
Now, I'm no expert on namespaces, but it looks to me like you declared a write function in the mapfile namespace, but when you wrote the function's implementation, you did not specify the mapfile namespace. Without specifying it, the function defaulted to the std namespace. Perhaps it should be:
Code:
void mapfile::write(const map<string, string> & m, ofstream & file)
You'll need to do the same for the read function as well. The other errors regarding boost stuff can probably be fixed by adding "-lboost" to the g++ command line. Though, you may need to do some reading to find out exactly what the library name is that you need to link against.
You didn't tell the linker that you are linking to the boost library. It's not a compile time error, but a link time error (hence why there are no line numbers).
The fact that the error is not reported until link time does not necessarily mean it is an error in the way the program is linked (such as a missing library). In this case, I doubt the problem is a missing library.
In code with messy templating (most of boost) it is very hard to get certain errors to show up at the right time or in an understandable form.
If you pass an impossible parameter type to an ordinary function, the compiler can easily report an understandable error. Also if you pass a nearly right parameter type to an ordinary function, the compiler has a wide range of automatic casts it can use to try to get to the right type.
But passing the wrong parameter type to a function whose parameters are templated (most boost functions) gives the compiler no good way to identify and report your error.
There are extra complications to passing a quoted string as a parameter for which the type must be inferred from a template definition.
I don't know what the parameter type is for boost::regex::assign but a quick look at your error messages makes me suspect the quoted strings in
Now, I'm no expert on namespaces, but it looks to me like you declared a write function in the mapfile namespace, but when you wrote the function's implementation, you did not specify the mapfile namespace. Without specifying it, the function defaulted to the std namespace. Perhaps it should be:
Code:
void mapfile::write(const map<string, string> & m, ofstream & file)
Didn't help.
Quote:
Originally Posted by Dark_Helmet
You'll need to do the same for the read function as well. The other errors regarding boost stuff can probably be fixed by adding "-lboost" to the g++ command line. Though, you may need to do some reading to find out exactly what the library name is that you need to link against.
Code:
/usr/bin/ld: cannot find -lboost
collect2: ld returned 1 exit status
Well, like I said, I'm not an expert on namespaces. You need to go find a resource that explains what the correct syntax is to not only declare the function as part of a namespace, but to also write the implementation in the proper namespace.
My only experience with namespaces is when dealing with classes:
/usr/bin/ld: cannot find -lboost
collect2: ld returned 1 exit status
The "-lboost" was a guess. You need to review the boost documentation to find out how to include their code with your program. I don't use it. So I don't know. Typically, the method is to add "-l<somename>" to the g++/gcc command line. You replace <somename> with whatever the docs tell you. If you don't have any boost documentation, a Google search for a boost tutorial ought to get you the info you need.
Last edited by Dark_Helmet; 12-28-2010 at 03:26 PM.
Well, like I said, I'm not an expert on namespaces. You need to go find a resource that explains what the correct syntax is to not only declare the function as part of a namespace, but to also write the implementation in the proper namespace.
Defining in a namespace uses the same syntax as declaring in a namespace. (Your suggestion extrapolated the way things work for a class in a way that is not correct for a namespace).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.