Discussion:
[Dev-C++] Adding my own Lib files to Project
Napoleon Ahiable
2002-08-26 13:19:02 UTC
Permalink
Hello,
How do I go about adding my own library files that to a project I'm working on. I have some files which I think are general enough that I put them in C:\***\lib. In order to add these files to a project I have the appropriate include statements. and added the path to the library to Project\Project Options\Files.Directories. I get the following Linker error:

C/CppLab/Winnie/main.cpp:21: undefined reference to `Win::ClassMaker::ClassMaker(char const *, HINSTANCE__ *)'
C/CppLab/Winnie/main.cpp:23: undefined reference to `Win::Maker::Maker(char const *, HINSTANCE__ *)'
C/CppLab/Winnie/main.cpp:25: undefined reference to `Win::Maker::Create(Win::Controller &, char const *)'

I also added the path to Tools\Compiler Options\Directories which also gives me the same error message. When I copy all the files into the same directory It compiles without errors. What am I doing wrong ?

Napoleon.
Abhijit Shylanath
2002-08-26 15:25:02 UTC
Permalink
Post by Napoleon Ahiable
Hello,
How do I go about adding my own library files that to a project I'm
working on. I have some files which I think are general enough that I put
them in C:\***\lib. In order to add these files to a project I have the
appropriate include statements. and added the path to the library to
Project\Project Options\Files.Directories. I get the following Linker
C/CppLab/Winnie/main.cpp:21: undefined reference to
`Win::ClassMaker::ClassMaker(char const *, HINSTANCE__ *)'
C/CppLab/Winnie/main.cpp:23: undefined reference to
`Win::Maker::Maker(char
const *, HINSTANCE__ *)'
C/CppLab/Winnie/main.cpp:25: undefined reference to
`Win::Maker::Create(Win::Controller &, char const *)'
I also added the path to Tools\Compiler Options\Directories which also
gives me the same error message. When I copy all the files into the same
directory It compiles without errors. What am I doing wrong ?
Napoleon.
I think you're getting confused between libraries and header files. Copy
these files to `c:\***\include'. They should work. A reply explaining all
this was posted by Elizabeth, but it seems to have missed you, so I'm
sending this to your account directly also.

___________________________________________________________

Abhijit Shylanath

E-mail: ***@gmx.net || ***@bigfoot.com
Web-site: http://mudeth.tripod.com/
Napoleon Ahiable
2002-08-26 15:48:11 UTC
Permalink
----- Original Message -----
From: "Abhijit Shylanath" <***@gmx.net>
To: "Napoleon Ahiable" <***@softnasolutions.net>; "Dev-C++ Mailing
List" <dev-cpp-***@lists.sourceforge.net>
Sent: Monday, August 26, 2002 6:22 PM
Subject: Re: [Dev-C++] Adding my own Lib files to Project
Post by Abhijit Shylanath
I think you're getting confused between libraries and header files. Copy
these files to `c:\***\include'. They should work. A reply explaining all
this was posted by Elizabeth, but it seems to have missed you, so I'm
sending this to your account directly also.
Abhijit Shylanath
Web-site: http://mudeth.tripod.com/
Hi,
Are you saying that the name of the directory makes a difference ? The ***
in my mail stans for projects. If by *** you are implying Dev-Cpp, then that
is what I don't want to do. I would not like to mix my files with those that
came with the compiler. My full path is C:\Projects\Lib. Do you mean I
should change Lib to include and add the path to where please explain.

Thanks.

Napoleon.
Elizabeth Barham
2002-08-26 16:25:07 UTC
Permalink
Look under:

Project->Project Options->Files/Directories

In that dialog there is a sub-tabbed thing, and the tabs are:

Library Directories, Include Directories, Resource Files, Resource Directories

If the libraries you need to link in to your application reside
somewhere beside the normal place ([DEV-C++_HOME]/lib or the
mingw-specific area) then you need to tell the linker about that
directory else it won't know where to look.

You add these directories using:
Project->Project Options->Files/Directories->Library Directories

These are *library* files and are not the same as include files.

Include files just tell the compiler (and your code) certain function
definitions (the signature of the function) and say to the compiler
"look, I don't have this code *now* but later on, when this program is
linked into an executable, somehow, someway, a function that matches
the signature in the header file will be provided".

So, anyway, after you compile your code using these header files
(often times referred to as "include files"), it's time to link it all
together. This is where the libraries come in - libraries provide the
actual code itself (not 100% accurate in that DLL's are used, but the
concept is the same: the library provides the implementation of the
functions defined in the header/include files).
Post by Napoleon Ahiable
Are you saying that the name of the directory makes a difference ?
The *** in my mail stans for projects. If by *** you are implying
Dev-Cpp, then that is what I don't want to do. I would not like to
mix my files with those that came with the compiler. My full path is
C:\Projects\Lib. Do you mean I should change Lib to include and add
the path to where please explain.
Right, you don't want to mix them with the standard header files; the
C:\Projects\lib is probably just an example.

Let's say I want to build a project entitled "terminal_library" so I make
a special directory (or folder) entitled "terminal_library_project"

mkdir terminal_library_project
cd terminal_library_project

I then hack away and build a DLL that resides within
terminal_library_project:

terminal_library_project:
terminal_library_a.c
terminal_library_a.h
terminal_library_a.o
terminal_library_b.c
terminal_library_b.h
terminal_library_b.o
terminal_library.dll
terminal_library.dll.a
terminal_library.a
terminal_library.def

Anyway, that is done so then I go over to a different folder to work
on the "terminal project" itself (which uses code in the
terminal_library).

cd ..
mkdir terminal_project
cd terminal_project

In the source files of terminal_project are things like this:

#include "terminal_library_a.h"

The problem with just stating this is that during the compile, the
compiler cannot automatically determine where to find
"terminal_library_a.h". In order for it to find it, I need to tell the
compiler where it is located, which is where:

Project->Project Options->Files/Directories->Include Directories

comes into play. I add "terminal_library_project" to this list of
include directories and it compiles into object code fine *but* it
fails to link with those nasty error messages you mentioned
earlier. Why is this? Because in the same way that the compiler needed
to know where to find the include files it also needs to know where to
find the library files, so I add "terminal_library_project" to the

Project->Project Options->Files/Directories->Library Directories

And this tells the *linker* where to find the *libraries*.

Elizabeth
Carlos García del Monte
2002-08-26 17:19:11 UTC
Permalink
I don't know if I sent this message to the right direction or not, I post it
again.

I have a couple of files:
file.h and file.cpp
which I want add to a project, but which I'll want add to other projects, too.
So I think make a library file, libfile.a.
I compile in command line g++ -c file.cpp
Then I do ar -r libfile.a file.o
Then ar -s libfile.a
I copy it to c:\dev-cpp\lib\
I put in options (either project if it is organized as project or compiler if
simply mainfile.cpp #include "file.cpp")
-lfile, or -llibfile or -libfile or -lfile.a or -llibfile.a, but depending on what
I use I get or it does not find it or undefined references. It happens the same if
I leave libfile in the same directory than the rest of the project (one single
more file, mainfile.cpp).

What's my error? I mistake binutil? (ar -s = ranlib)

P.S. - In my computer (windows 2000, Intel III x86 6.5.5), when I type in the
command line ar -pv file it starts beeping continuosly, the command line does not
respond anymore and that continues after it has printed all. I had to restart the
computer. (I didn't proved without v[verbose], but surely it would do the same).
Elizabeth Barham
2002-08-26 20:30:06 UTC
Permalink
I have a couple of files: file.h and file.cpp which I want add to a
project, but which I'll want add to other projects, too. So I think
make a library file, libfile.a. I compile in command line g++ -c
file.cpp Then I do ar -r libfile.a file.o Then ar -s libfile.a I copy
it to c:\dev-cpp\lib\ I put in options (either project if it is
organized as project or compiler if simply mainfile.cpp #include
"file.cpp") -lfile, or -llibfile or -libfile or -lfile.a or
-llibfile.a, but depending on what I use I get or it does not find it
or undefined references. It happens the same if I leave libfile in the
same directory than the rest of the project (one single more file,
mainfile.cpp).
What's my error? I mistake binutil? (ar -s = ranlib)
It would be -lfile as the linker inserts 'lib' and adds on '.a'.

You'd need to add in the library directory C:\dev-cpp\lib, however,
for the linker to find it.

For example,

g++ -o test test.cpp -LC:\dev-cpp\lib -lfile

The -L says to look in C:\dev-cpp\lib for the library file
"libfile.a". If the library file is in the same directory, you could
use -L. .

Elizabeth
Carlos García del Monte
2002-08-28 10:47:05 UTC
Permalink
I was using template functions, I experimented without template and then it
worked. It is prohibited using templates for libraries?

Napoleon Ahiable
2002-08-27 11:59:04 UTC
Permalink
Hello Elizabeth,

I have tried your solution without success. I think it's me doing something
wrong so I will elaborate my problem below exactly as it is then may be you
can point me in the right direction. I have 3 main paths I'm dealing with
they are: (1)C:\Projects\Windows, (2)C:\Projects\Windows\Lib, and
(3)C:\Projects\Resources.

Path 1 contains the files
Main.cpp,Ctrl.cpp,Ctrl.h, View.h.

Path 2 contains the files
Maker.cpp, Maker.h, Window.h, Procedure.cpp, Procedure.h, Class.cpp,
Class.h, Icon.cpp, Icon.h, Control.h and Canvas.h

Path 3 contains
Main.Ico, Script.rc, Resource.h

This is the way I tried to biuld the library. I created a DLL project and
added all the files from path 2 to it as they are. But I get loads of error
messaged when I compile.

The need to create a personal libary I guess becomes inevitable with time.
as it becomes obvious that certain classes and functions lend themselves to
reuse. If any one can write a little tutorial on how to build such a library
It will be much appreciated. Up untill now I have only written programs with
all the files in one directory but now I feel the need to start writting
libraries.

Thanks to anyone who will help.

Napoleon.
Continue reading on narkive:
Loading...