extern and linker error

S

Seungbeom Kim

Thanks for the explanantion. I couldn't have posted the original code as that is thousands of lines of C++ code, spread over hundreds of files. I was getting a linker error and posted just the lines that I thought relevant. I missed the const (and a
lot of other code).

When people say "post complete compilable code which demonstrates your
problem", they don't mean "post the complete code from which you got
your problem first"; you should first construct a minimal compilable code
that has the same problem, test it, and post it. You did something very
similar; you constructed a minimal code that you think has the same problem:

// foo.h
extern int x;

// foo.c
int x = 5;

// bar.c
#include foo.h
int y = x; // <--- linker error here

but you didn't actually test it and confirm that it had the same problem.
(In this process, you often realize the problem and solve it yourself.)

http://www.parashift.com/c++-faq/how-to-post.html#faq-5.8
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top