Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linking with a foreign library

Status
Not open for further replies.

satellite03

IS-IT--Management
Dec 26, 2003
248
IN
hi, i want to link with a downloaded library to my C program .....in the readme file of the manual i found they have specified a header .

so i wrote like below

#include "specified header.h"

also tried with...

#include<specified header.h>

but no successes .....at the compilation time i am getting message (in VC++) file or directory does not exist!!

why?

do i need to explicitly define the path?

i tried that also...

my program is in c:\pg\abc.cpp

foreign library in c:
and that specifed header is in c:\folder\specifed header.h

i tried with #include c:\\folder\\specifed header.h

.......still getting file /directory does not exist at the compilation time !!

so my question is how to link with a foreign library?


any advice or suggestion
 
usually with any C compiler, you can specify the header file lookup path with -I on the compile line and the library lookup path with -L (say &quot;cc -I /home/ranga/myinc/ -L /home/ranga/mylib main.c -lnewlib&quot;). i guess vc++ has some dialog box that lets you specify these paths (separately). since i dont know about vc++, i can only suggest you explore all the menu options etc.
 
thanks Rangan

can anubody say,what should be the proper directives so that i can link with a foreign library.(i am usuing vc++ )

Rangan is telling about the command line.....but from inside the IDE(vc++) what should i write.

i have downloaded this library

then

i have simply clicked on the mkallmsc.bat to get executables.( dos window came and blinked away quickly)

then

i tried to write a small code.....the library has suggested to write #include &quot;m_apm.h&quot; at the begining of the code...

i did that also..

but at the compilation time it is saying :

fatal error C1083: Cannot open include file: 'm_apm.h': No such file or directory
Error

and surprisingly the demo code given in the library itself is giving the same kind of error.


can anybody tell me how can i fix this problem?

thanks
 
In VC++ Version 6, you press ALT-F7
Select the C++ Tab
Select Preprocessor from the Category list
In the &quot;Additional Include Directories&quot;, type in the location of where you unzipped the 3rd party library


--
 
hi salem... thanks.

but still getting problem.

i did as you suggested....after that i opened demo of pi2.c ....its compiling ...but at the execution time i am getting 21 error..and most of them are from library variable.

its saying &quot;unresolved external symbols&quot;

so i think its not linking properly...is not it?

probabily my library has not been built up correctly...you know, i saw in the &quot;readme&quot; file in the library instructions like this

for
========================
Microsoft Visual C++ 6.0
========================
run : mkallmsc.bat (builds library + 4 executables)

so
i simply clicked on mkallmsc.bat.... a DOS window came and blinked away quickly.

although it clearly says to &quot;run&quot; but i could not bcoz when i opened mkallmsc.bat in VC++ IDE &quot;execute&quot; option was inactive.

....so i dont know even whether my library has been built up or not ...bcoz i dont see any changes in the library after clicking on mkallmsc.bat.

anyway,

can you suggest what is the problem now ??



 
> its saying &quot;unresolved external symbols&quot;
In pretty much the same way that you add additional paths to tell VC++ where to find additional .h files, there is a similar dialog for specifying the names and locations of additional object libraries.



--
 
>>In pretty much the same way that you add additional paths to tell VC++ where to find additional .h files

hmmm...but there is two >h files only and that i have specified in &quot;Additional Include Directories&quot; by typing the location of library C:\mapm\mapm_4.9


>>there is a similar dialog for specifying the names and locations of additional object libraries.

i dont find any .obj files at all in the library.....what dialogue you are talking about?

&quot;specifying the names and locations of additional object libraries.&quot;

----what is the name of this dialogue box ?

i have checked all the options but none found suitable.

thanks


 
You need to build the library first

1. Open a new console window, so you have a c:\> prompt
2. cd to the directory where MKALLMSC.BAT resides
3. Do this bit, which is a comment at the start of the MKALLMSC.BAT file
[tt]rem Note: run VCVARS32.BAT in /bin directory of VCPP first to set
rem the environment variables.[/tt]
Exactly where this is depends on where you installed your compiler.

So basically, you type in
[tt]d:\path\VCVARS32.BAT
MKALLMSC.BAT[/tt]

When you run the 2nd one, you should see lots of compiling taking place. It finished so quickly when you ran it because I guess it didn't know what 'cl' was (not having run VCVARS32.BAT)

The end result of this should be a file called mapm.lib

Then check the ALT-F7 dialogs again - I think there is a tab called link, where you specify the directory and name of the library you've just created.

--
 
hi salem,

your comment

>> Open a new console window, so you have a c:\> prompt
>>cd to the directory where MKALLMSC.BAT resides


yes i did it...
so i am now on C:\mapm\mapm_4.9\dos_nt_9x\ MKALLMSC.BAT i pressed ENTER.

and got some message in prompt like

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\mapm\mapm_4.9\dos_nt_9x>MKALLMSC.BAT



Running build file for MAPM library with Visual CPP under Win NT/9x ...

Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\map*.obj
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\mapm.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

map*.c
fatal error C1083: Cannot open source file: 'map*.c': Invalid argument
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\map*.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

calc.c
fatal error C1083: Cannot open source file: 'calc.c': No such file or directory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;calc.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\calc.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

validate.c
fatal error C1083: Cannot open source file: 'validate.c': No such file or direct
ory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;validate.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\validate.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

primenum.c
fatal error C1083: Cannot open source file: 'primenum.c': No such file or direct
ory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;primenum.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\primenum.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

cpp_demo.cpp
fatal error C1083: Cannot open source file: 'cpp_demo.cpp': No such file or dire
ctory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;cpp_demo.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\cpp_demo.obj

C:\mapm\mapm_4.9\dos_nt_9x>





......this is the response i got in the command prompt.




your comment....

&quot; 3. Do this bit, which is a comment at the start of the MKALLMSC.BAT file...&quot;


I DID not do it....i could not understand you.
is it necessary??

how can i do it ?

VCVARS32.BAT file exsits in the folder &quot;C:\Program Files\Microsoft Visual Studio\VC98\Bin&quot;

.....command prompt is not accepting the path bcoz there are gaps(spaces)in the path.

if it is really necessary, then plz give me steps
what i should do now.



i think my library has not been built up.

thanks





 
> command prompt is not accepting the path bcoz there are gaps(spaces)in the path.
You put the whole thing in double quotes.
And it really does go on one line, the line in my example has been wrapped by this board.

This is the session I created
Code:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>cd C:\junk\mapm

C:\junk\mapm>&quot;C:\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.BAT&quot;
Setting environment for using Microsoft Visual C++ tools.
C:\junk\mapm>mkallmsc.bat

Running build file for MAPM library with Visual CPP under Win NT/9x ...

Could Not Find C:\junk\mapm\map*.obj
Could Not Find C:\junk\mapm\mapm.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

MAPM5SIN.C
MAPM_ADD.C
MAPM_CPI.C
MAPM_DIV.C
MAPM_EXP.C
MAPM_FAM.C
MAPM_FFT.C
MAPM_FLR.C
MAPM_FPF.C
MAPM_GCD.C
MAPM_LG2.C
MAPM_LG3.C
MAPM_LG4.C
MAPM_LOG.C
MAPM_MUL.C
MAPM_POW.C
MAPM_RCP.C
MAPM_RND.C
MAPM_SET.C
MAPM_SIN.C
Generating Code...
Compiling...
MAPMASIN.C
MAPMASN0.C
MAPMCBRT.C
MAPMCNST.C
MAPMFACT.C
MAPMFMUL.C
MAPMGUES.C
MAPMHASN.C
MAPMHSIN.C
MAPMIPWR.C
MAPMISTR.C
MAPMPWR2.C
MAPMRSIN.C
MAPMSQRT.C
MAPMSTCK.C
MAPMUTIL.C
MAPMUTL1.C
MAPMUTL2.C
Generating Code...
Microsoft (R) Library Manager Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

calc.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

validate.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

primenum.c
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

cpp_demo.cpp
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


C:\junk\mapm>dir *.lib
 Directory of C:\junk\mapm

11/02/2004  10:02           132,520 mapm.lib

--
 
hi salem,

same thing i did but no sucesses.

i am wrting below what i did:

C:\mapm>&quot;C:\Program Files\Microsoft Visual Studio\VC98\Bin\VCVARS32.BAT&quot;
Setting environment for using Microsoft Visual C++ tools.

then

i browse into directory where mkallmsc.bat exists.

so, i did....

C:\mapm\mapm_4.9\dos_nt_9x>mkallmsc.bat ENTER




Running build file for MAPM library with Visual CPP under Win NT/9x ...

Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\map*.obj
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\mapm.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

map*.c
fatal error C1083: Cannot open source file: 'map*.c': Invalid argument
Microsoft (R) Library Manager Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\map*.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

calc.c
fatal error C1083: Cannot open source file: 'calc.c': No such file or directory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;calc.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\calc.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

validate.c
fatal error C1083: Cannot open source file: 'validate.c': No such file or direct
ory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;validate.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\validate.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

primenum.c
fatal error C1083: Cannot open source file: 'primenum.c': No such file or direct
ory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;primenum.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\primenum.obj
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

cpp_demo.cpp
fatal error C1083: Cannot open source file: 'cpp_demo.cpp': No such file or dire
ctory
Microsoft (R) Incremental Linker Version 6.00.8168
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : fatal error LNK1181: cannot open input file &quot;cpp_demo.obj&quot;
Could Not Find C:\mapm\mapm_4.9\dos_nt_9x\cpp_demo.obj

C:\mapm\mapm_4.9\dos_nt_9x>



i think i have done it correctly,.. but my library is not building.

is there anything wrong???


can you plz tell me from which website you have downloaded that library.... what is the version of that library?











 
You have extracted ALL the files from the zip file, and not just the batch file?

I'd do 'extract all' from the zip file again, just in case you've managed to corrupt the batch file.

> can you plz tell me from which website you have downloaded that library
The one in your 2nd message in this thread.



--
 
>You have extracted ALL the files from the zip file, and not just the batch file?

yes....i have extracted all files folders carefully.

i did select all > extract to folder.

any way, i am sure all has been extracted.

i did not download from that link.....i downloaded from link ICEwalk (something like that)..

i could not remember that link ....so i gave the link of the home page of MAPM library to make you understand what i am doing...

however...it should not be different if i download from mirrors.


ok, i will now try the same thing by downloading the library from the home page of MAPM itself.

let me check again by downloading from your link.

thanks





 

hi salem,

i just downloaded the library and build it.

now its showing everything what you have got....mamp.lib has been created perfectly.

but why the demo code is not working?

..probabily library is not able to link...

after building the .lib ,i created a new project and and a new C/c++ source file....i typed the demo code in it.

then ALT-F7 setting>C/C++>category>preprocessor>additional include directory>c:\mapm-49

then i tried to compile and execute it....but got 18 errors!!


your comment:

&quot;Then check the ALT-F7 dialogs again - I think there is a tab called link, where you specify the directory and name of the library you've just created.&quot;

i went to Link tab also...and there i found 2 dialogue box.
1.output file name --->this contains : Debug/new.exe

2.object/library modules --->this contains : kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

i was trying to run pi demo code...but got errors...

can you tell what changes do i have to do in Link tab??


 
> setting>C/C++>category>preprocessor>additional include directory>c:\mapm-49
Sounds good so far.
I trust that is the directory where the header files are to be found.

> then i tried to compile and execute it....but got 18 errors!!
And they would be?
Post them!

> 2.object/library modules --->this contains
This is pretty close
Select &quot;Input&quot; from the Category list
Add mapmp.lib to the object/library modules list
Add c:\mapm-49 to the additional library path.

--
 

hi, salem

i have made it....its working now..i tested with the demo code....its woking fine.

thanks a lot.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top