After about 25 years of not using C I find myself once again needing to program in it. The coding is going ok and I have gotten much of what I needed to get done already. The problem is I am having a hard time linking to library I built of subroutines that I wrote and built into a library using the IDE, the library built fine and I wrote a header file with the prototypes for the library subrotines. I put the library file in the library folder and did the same with the .h file.
Made changes to the original program that I used to validate the code so it would use library functions, I did include my .h file. When the project was linking all the library functions came back as unresolved externals.
Can someone give me some direction to help solve this issue/problem?
Thanks
wade
Did you create a .lib or .dll file?
Is the .lib and the .dll file in the path of the .h file, if you created a .dll file?
Is the path containing the .lib in the library path setting of the project included?
I created a .lib file
The path containing the .lib file is in the path setting of the project. After having some problems I just put the .lib file in the same directory with the other Pelle C library files.
Thanks
wade
In your .h file add the line
#pragma lib(libraryname)
It's possible the linker doesn't know where to look.
I added the following to the .h file
#pragma comment( lib, "environ.lib" )
and got the same unresolved externals.
As a test I renamed the .lib in the folder and tried to build and it said it did not find the folder. I did this to see if the linker was looking for and finding the .lib file, it was finding the file when named correctly.
Still Stumped,
wade
Quote from: wwbrown on December 06, 2010, 05:19:22 PM
I added the following to the .h file
#pragma comment( lib, "environ.lib" )
and got the same unresolved externals.
As a test I renamed the .lib in the folder and tried to build and it said it did not find the folder. I did this to see if the linker was looking for and finding the .lib file, it was finding the file when named correctly.
1.) If you build your project with the IDE, you con also add the in the project options at the linker tab.
2.) Have you build the library and program with the same compiler options. When you compile the library and the program f.e. with different calling conventions you can add the lib and the linker would not find your functions because they have different names.
I checked the compiler options and they were all the same. Tried to build the app again and same unresolved externals, very strange I must have done something exceedingly stupid. Let me step through the steps I made:
1) I wrote up the main () and functions all in separate files, putting the prototypes in the main() file at first. The functions had been deBugged and validated before combining them in one app. The main() ran fine and returned the correct values.
2) I took the function files out of the original project and created a new project (Win 32 Static Lib) took the function prototypes out of the original main() and put them in a new file called environ.h using the IDE editor. I put #include"C:\Envlib\environ.h" in the new main there were still #include <stdio.h> and #include <math.h> in the new main(). The linker finds environ.h I know because I commented out one of the function prototypes in the header file and got the no prototype for the function I commented out. I commented out the function prototype just to see if the environ.h was actually being included. I have included the header file environ.h maybe someone can see a problem.
Thanks
wade
Here is the header file
/*
Header file for the environ library. environ.h
*/
float densityAir(float, float, float);
float densityAltitude(float);
float dewPoint(float, float);
float calcSpeedSound(float, float, float);
float pressAltitude(float);
float altPressure(float);
Unresolved externals are usually because the linker can't find the library...
Where is the environ library located?
You can use either a #pragma lib(<libraryname>) or add it to the linker's library list.
Could you post a short version of your project so we can check compile and link options (your main and library fuctions can contain only the return).