I am attempting to compile C code which accesses the libredwg library through a header file: #include "dwg.h"

When I attempt to compile my code using gcc -o ldwg load_dwg.c, I get the following error: undefined reference to `dwg_read_file'.

However, if I load the file in Kdevelop, I get no such error message. If I change `dwg_read_file' to 'foo' (which is obviously not defined), then I get an error Implicit declaration of function 'foo' is invalid in C99 [-Wimplicit-function-declaration] so I know that the function is being read.

How can I make gcc see the function definition?

  1. You need a header with declaration of the function foo. You can't just change the function or method on its own and get by.
  2. I see priors on the error "undefined reference to `dwg_read_file'." in a simple google so read those two.
  3. "GNU LibreDWG has a development and general discussion mailing list: " which means it's best to join that and ask those that use this library I haven't used.

Thanks for the response; it is appreciated.

  1. I am aware of that. I was simply changing the reference in Kdevelop to accertain whether the function was being read. When I changed the reference, I got the error, which demonstrated that the lack of error meant that the dwg_read_file function was being correctly accessed by Kdevelop.

  2. Thanks. I had googled, but I had removed the specific function name from the search string because I thought that it was likely to be a genericproblem with gcc. As you point out, the function itself appears problematic.

  3. Thanks, again. I will join that and ask there, as you suggest. Some of these lists and forums can be very intolerant of what they consider to be stupid questions, so I am a little wary of approaching them.

Aha, I think I see your real question now. It's something like: Why does (blank) work in Kdevelop but not gcc?

I would be guessing that the settings, paths and libraries differ from one system to the other. As I don't use your noted library I can't do the detective work for you. Sorry but I missed the short version of your question such as "How do I use (blank) but with a gcc command line compile? My bet is there will be a make file in your future.

Frankly for whatever you are doing why not use Kdevelop, get it done and move to the next project?

Sorry; I was a bit convoluted.

No, I wouldn't expect you to do the detective work for me, that's no problem. The library comes with an 'examples' directory, but all the examples fail with the same 'Undefined references' error. There is a Makefile in there but running 'make' and compiling the object file doesn't resolve the errors.

I am on the dwglib list and have posted about this a few weeks ago, but it's not a terribly active list and I've yet to receive a response.

Obviously, if Kdevelop can reference the function, then if Kdevelop can compile the code, then it makes sense to go down that route. Kdevelop does have a handbook, but I'm afraid I have been using the lazy route and have been looking for a shortcut using google. I suppose I need to knuckle down and do some reading.

As an aside, one of the threads turned up using google with the function name as you suggested is a question asked by myself in 2012! So it appears that I have been working on this for at east eight years! Hell's teeth!

Just a thought.

Would you please confirm that I'm using the make file correctly?

make clean
make
gcc -c load_dwg.c // load_dwg is one of the examples 
gcc -o ldwg load_dwg.o

As to the make clean that part looks fine. As to the make, I can't proceed. I would have to have the project up in Kdevelop then explore all the settings and options for the project to find where there is a difference. I don't know of any automated way to discover the differences.

For example Kdevelop may list libraries required but your gcc make file may omit same. Also there may be gcc compile flags that differ.
"This is the way" we'd have to figure out what's different. Think of it was a Waldo hunt but for programmers.