473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

how to create a user defined library and add functions to it?

i use turbo c++ v3.0.
i tried to create a library and add the following functions to it.
int prime(int);
long fact(long);

i used the standard procedure for doing so.
yet when i tried to use my functions after including the header file i had created, a linker error occured.

linker error : undefined symbol fact(long) in module noname00.cpp.

now i had used 'int' in my program which means that it had identified the function in my library, yet it refused to work.
is it because my compiler is outdated or because of some other flaw in the program.
for the record i had applied the procedure as stated in yashwant kanetkar's book 'Let Us C'.
please advise on how to correctly create a user defined library.
Feb 23 '12 #1

✓ answered by Banfa

When you create a library the output is 2 files, a header to be included into your source code that tells the compiler about the functions in the library and a binary library file (.lib or .a) that is passed to the linker and contains the binary code of the functions in the library.

If you don't pass the binary library file to the linker you get unresolved (or in your case undefined) symbols because the linker can not find the binary code that the compiler has told it to expect to find.

So it is not because you tool-set is outdated, it is because you are not passing the binary library file to the linker.

3 4486
Banfa
9,065 Expert Mod 8TB
When you create a library the output is 2 files, a header to be included into your source code that tells the compiler about the functions in the library and a binary library file (.lib or .a) that is passed to the linker and contains the binary code of the functions in the library.

If you don't pass the binary library file to the linker you get unresolved (or in your case undefined) symbols because the linker can not find the binary code that the compiler has told it to expect to find.

So it is not because you tool-set is outdated, it is because you are not passing the binary library file to the linker.
Feb 23 '12 #2
true.
I created three files.
A '.h. file, a '.lib' file and a '.obj' file.
i put the '.h' file in the include folder and the other two in the lib folder.
yet the problem persists.
do i have to include the binary library file too or just save the files in different locations.
Feb 25 '12 #3
Banfa
9,065 Expert Mod 8TB
You shouldn't include the binary library that wont work. You need to all it to your link or build command line.

For example if you were using the following build line

gcc -Wall -pedantic source.cpp

you would need to use

gcc -Wall -pedantic source.cpp -Wl,-l<LibraryFileName>

to pass the library to the link stage of the build.
Feb 27 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Igor2004 | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string...
0
by: Igor Nikiforov | last post by:
Ladies and Gentlemen, I would like to offer you the following string functions Transact-SQL GETWORDCOUNT() Counts the words in a string GETWORDNUM() Returns a specified word from a string...
10
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to...
5
by: Neil Zanella | last post by:
Hello, I need to access some user defined utility functions from within my ASP.NET pages. I wonder whether there is a way to do this. I do not want to use inheritance. I just want to be able to...
2
by: Ellis Yu | last post by:
Hi all, Thanks for Jim M and Herfried K Wagner first. I'd posted a question here about building dll output file in standand edition. It works after changing outputtype to "library". And now I...
1
by: Otto Blomqvist | last post by:
Hello ! I have several functions that are compiled as .so and runs pretty well under PSQL. However I would like to be able to return errors (for debugging) using something like this ...
4
by: rathika2786 | last post by:
Hi All, i m a new user to visual basic 6.can some one explain to me in detail as to how to create user defined data types?wat reference i should create for it?how to craete references?where should i...
1
by: Clay Hobbs | last post by:
I already know how to make user-defined exceptions, like this one: class MyException(Exception): pass But for a module I'm making, I would like to make a warning (so it just prints the...
0
by: Andrii V. Mishkovskyi | last post by:
2008/6/18 Clay Hobbs <clay@lakeserv.net>: Use 'warnings' module. http://docs.python.org/lib/module-warnings.html -- Wbr, Andrii Mishkovskyi.
0
by: jefftyzzer | last post by:
Friends: In v8 or v9 LUW, if I were to write (in Java or C) my own user-defined aggregate function, would I be able to use it in an OLAP windowing clause as I could use, e.g., COUNT or SUM? ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.