www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/16/00:01:15

Message-ID: <000a01be111e$3c3749e0$c5223182@marst96.m.resnet.pitt.edu>
From: "mark reed" <marst96+@pitt.edu>
To: <djgpp AT delorie DOT com>
Subject: undefined references and .h's .o's .a's
Date: Mon, 16 Nov 1998 00:01:56 -0500
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
Reply-To: djgpp AT delorie DOT com

I have a main.cpp that includes a foo.h file. In that .h file, are a bunch
of function declarations. like this
void foo();
in a foo.cpp file, i define the functions from foo.h. Now if i include foo.h
from main.cpp, it gives me lots
of undefined references.

So then i compiled foo.cpp, using gcc -c foo.cpp to create a .o file. then I
did gcc -o main.exe main.cpp foo.o,
and still get the undefinced references.
then i made a library, using ar rvs foo.a foo.o and then did gcc -o main.exe
main.cpp foo.a, which also didnt
work. Also did gcc -o main.exe main.cpp foo.cpp didnt work either.
Then i made every function declaration and definition extern void foo();
but still nothing works.

Then just now i created test files, err.cpp argh.h and argh.cpp, to see if i
would get undefined references
again and i did gcc -o err.exe err.cpp argh.cpp
and it worked.

so i am thinking that the problem is my typedefs and structs -
typedef float matrix[4][4]
and
struct vecType
{
 float x,y,z;
} vector,*vectorPtr

an example function:
void addVectors(vectorPtr dest, vectorPtr left, vectorPtr right);
undefined reference to 'addVectors(vecType *, vecType *, vecType *)'   <--
the error

when these two guys(typedef or struct) are passed as parameters to a
function, then that function
becomes an undefined reference in the main.cpp file. But if i put a function
like this in the foo.cpp
file, it is fine to use in the main.cpp file.
void thisworks(int a);

and both the main cpp file, and the other one include a separate .h file
that does the struct and typedef

anybody know what is wrong?
thanks
Mark - marst96 AT pitt DOT edu





- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019