![]() |
|
#1
|
|||
|
|||
Help With Static Libraries?So, basically, I'm writing a test static library + application in Dev-C++ in order to understand how I can get it to function properly, however, despite endless google searching for 6 hours flat, nothing has helped.
The library contains a single function which takes an integer parameter, and returns that integer multiplied by 5. The actual application gets an integer from the user, and passes it to the function in the library, and then prints out the result. The actual result is the following: ![]() The source is as follows: Static Library (Sum.a): main.c: CPP / C++ / C Code:
sum.h: CPP / C++ / C Code:
Test Application [test.exe]: main.cpp: CPP / C++ / C Code:
My compile logs, incase they're of any help, are as follows: Sum.a Quote:
Test.exe Quote:
Anybody know what's going on? I've gone through a library worth of information online to no avail (excuse the pun). Thanks, ~Dark Dude~ |
|
#2
|
|||
|
|||
Re: Help With Static Libraries?Here is a complete, working example of using a static library.
CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Code:
Output of invoking gmake: Code:
Output of executing static_main: Code:
Note that only very minor differences to the Makefile should be required for those who are using Windoze. :davis: |
|
#3
|
|||
|
|||
Re: Help With Static Libraries?Quote:
I suggest that before putting a function into a library that you test the function in a "regular" program. Here is the function in a C program: CPP / C++ / C Code:
If you get a seg fault here, as I did, you know that the problem is with either the main() function or the Sum() function, and not due to some procedural error in putting the function into a library. I also suggest that you change project settings so that you turn on compiler warnings. If I compile with -Wall -W -pedantic, the compiler tells me: Code:
Running the program gives me a segfault. Fix the function. Thoroughly test the function. Then see what you have to do to get it into a library. This is a trivial function, so testing it is also trivial. Generally speaking, testing library functions is extremely important. Of course testing is always important, and of course, in general, you can't necessarily prove a function is correct just by testing. But, generally speaking, testing is easier (more time-effective) if you test it before going through the steps of putting it into a library. Regards, Dave |
|
#4
|
|||
|
|||
Re: Help With Static Libraries?Edit: Solved it with help of both previous posters
|
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| triangle (polygon), drawing, sizing, and rotation programme using linked lists... | promsan | C Programming Language | 12 | 14-May-2007 14:03 |
| Anything i can do with static addActionListener(this); | RobRob47 | Java Forum | 2 | 26-Mar-2007 12:17 |
| draw in image | jafar | FLTK Forum | 2 | 19-Sep-2006 10:51 |
| Handling keyup events. | harroldm | FLTK Forum | 3 | 24-Aug-2006 08:48 |
| Bloodshed Dev C++ Project Options | JdS | CPP / C++ Forum | 6 | 11-Nov-2005 17:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The