Hi,

I want to do this. Suppose I have a source file abc.c:

abc.c

int a

another source file test-lib.c which leverage a from abc.c

test-lib.c

#include "abc.c"

extern int a;

int main()
{
          return 0;
}

Now suppose abc.c is only available as abc.o (source code not available). And I want to link test-lib.o with abc.o using these commands

g++ -c test-lib.c
g++ -o op.o abc.o test-lib.o

I am getting this compilation error:

test-lib.o:(.data+0x0): multiple definition of `a'
abc.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status

I am not sure what went wrong. I did according to:
http://www.eskimo.com/~scs/cclass/notes/sx5d.html

Crying for help here.

Thanks.

#include "abc.c"

doesn't go together with

abc.c is only available as abc.o (source code not available)

Did you mean to #include "abc.h" perchance? abc.h should contain

extern int a;

Don't forget to delete line 3 in your test-lib.c

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.