NO

Author Topic: Newbie question  (Read 4500 times)

wwbrown

  • Guest
Newbie question
« on: December 06, 2010, 12:09:16 AM »
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

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: Newbie question
« Reply #1 on: December 06, 2010, 12:21:24 AM »
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?
---
Stefan

Proud member of the UltraDefrag Development Team

wwbrown

  • Guest
Re: Newbie question
« Reply #2 on: December 06, 2010, 12:42:32 AM »
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

CommonTater

  • Guest
Re: Newbie question
« Reply #3 on: December 06, 2010, 01:59:50 AM »
In your .h file add the line

#pragma lib(libraryname)

It's possible the linker doesn't know where to look.

wwbrown

  • Guest
Re: Newbie question
« Reply #4 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.

Still Stumped,

wade

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Newbie question
« Reply #5 on: December 06, 2010, 07:29:19 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.
best regards
 Alex ;)

wwbrown

  • Guest
Re: Newbie question
« Reply #6 on: December 06, 2010, 10:51:49 PM »
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);

CommonTater

  • Guest
Re: Newbie question
« Reply #7 on: December 06, 2010, 11:37:04 PM »
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.

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Newbie question
« Reply #8 on: December 09, 2010, 11:55:49 AM »
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).
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide