PLEASE HELP - Linkage problem in gcc 3.2.3 with arbitrary precision arithmetic

C

cpptutor2000

Could some C++ guru please help me? I am using a BigInteger class which
is really
a wrapper around a C source file(mpi.c) that does arbitrary precision
arithmetic operations. When I compile the C file using gcc -g -o mpi
mpi.c rng.c -lm
there are NO compilation or linking errors. However, when I try to
compile the
C++ wrapper class using g++ -g -o bigint bigint.C mpi.c rng.c -lm, I
get strange linkage problems that all the functions in the C
file(mpi.c) are 're-defined'. I have checked over and over, but there
is no re-definition of the functions. I have not posted the source
code, as it is fairly huge. Could someone provide some
ideas as to what might be going wrong? I am using gcc 3.2.3. Thanks in
advance for your help!
 
E

E. Robert Tisdale

Could some C++ guru please help me? I am using a BigInteger class which
is really
a wrapper around a C source file(mpi.c) that does arbitrary precision
arithmetic operations. When I compile the C file using gcc -g -o mpi
mpi.c rng.c -lm
there are NO compilation or linking errors. However, when I try to
compile the
C++ wrapper class using g++ -g -o bigint bigint.C mpi.c rng.c -lm, I
get strange linkage problems that all the functions in the C
file(mpi.c) are 're-defined'. I have checked over and over, but there
is no re-definition of the functions. I have not posted the source
code, as it is fairly huge. Could someone provide some
ideas as to what might be going wrong? I am using gcc 3.2.3.

Try

gcc -Wall -std=c99 -pedantic -c mpi.c rng.c

then

g++ -Wall -ansi -pedantic -g -o bigint bigint.C mpi.o rng.o -lm
 
A

Alf P. Steinbach

* (e-mail address removed):
Could some C++ guru please help me? I am using a BigInteger class which
is really
a wrapper around a C source file(mpi.c) that does arbitrary precision
arithmetic operations. When I compile the C file using gcc -g -o mpi
mpi.c rng.c -lm
there are NO compilation or linking errors. However, when I try to
compile the
C++ wrapper class using g++ -g -o bigint bigint.C mpi.c rng.c -lm, I
get strange linkage problems that all the functions in the C
file(mpi.c) are 're-defined'. I have checked over and over, but there
is no re-definition of the functions. I have not posted the source
code, as it is fairly huge. Could someone provide some
ideas as to what might be going wrong? I am using gcc 3.2.3. Thanks in
advance for your help!

You have probably #include'd [mpi.c], the function definitions, in
[bigint.C] or in a file #include'd by [bigint.C], instead of
#include'ing [mpi.h], just the function declarations.

In that case there are two resolution: (1) leave out [mpi.c] in the g++
command line (i.e. this is how you want it), or (2) change the #include.

Method (2) is the recommended one, because #include of definitions is
often very problematic.
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top