Solved

connect Lib with another Lib

Posted on 2003-11-28
9
380 Views
Last Modified: 2010-04-02
I build socket library in VC++ and I need to link it with ws2_32.lib
How can I do that?
0
Comment
Question by:amakalski
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 9838977
ive written libs before but never had to link with another yet. it didn't work if you just included the other library from settings or using the #pragma statement??
0
 
LVL 86

Accepted Solution

by:
jkr earned 250 total points
ID: 9839022
>>How can I do that?

The question is: Why would you want to do that? 'ws2_32.lib' is just the import library for 'ws2_32.dll'

But, 'lib.exe' (the library manager can do that: To combine libraries, specify the library filenames. You can add objects and combine libraries with a single LIB command.

E.g.

lib.exe mysock.lib ws2_32.lib /out:mysockws2_32.lib

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9839160
Exactly as you do this for exe project. Project - Settings - Link - Object/library modules. Type ws2_32.lib.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:amakalski
ID: 9839412
The thing is I am writing socket wrapper sockwrap.lib library, that uses ws2_32.lib. Later it will  be used in EXE project. So I don't want people who will use my lib in EXE project to link with my lib AND IN ADDITION link with ws2_32.lib. Can't I just link my lib with ws2_32.lib, so whoever use my lib will be automatically linked with ws2_32.lib ?

AlexFM,
If in LIB-type Project, I go to Project-Settings-Link Tab I don't see there Object/Library line (it's hidden). I know you right for EXE-type project it's there, but for LIB-type I just can't see it there.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9839428
>>Can't I just link my lib with ws2_32.lib

As a library usually is distributed a header file, I'd use PlanetCpp's suggestion of placing a

#pragma comment ( lib, "ws2_32.lib")

in it, which will take care of the problem.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 9839477
Right. Actually client's project will be linked to ws2_32.lib, but client doesn't need to do anything for this.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9839492
BTW, combining your lib with ws2_32.lib like

lib.exe mysock.lib ws2_32.lib /out:mysockws2_32.lib

would still work, also. But, you'd have to add that as a post-build step manually.
0
 

Author Comment

by:amakalski
ID: 9839540
I don't like #pragmas, so I will go with
ws2_32.lib /nologo /out:"lib\sockwrapD.lib"
And I don't need to add post-build step, I just set this manually in Project/Settings/Link Tab/'Project options' edit box
Since it's originated from jkr post, he will get the points
0
 
LVL 6

Expert Comment

by:PlanetCpp
ID: 9840573
>>I don't like #pragmas
its just a directive for the compiler to add the link to that lib file (in this use of pragma)
using the project settings instead of pragma is a small difference but actually combining both library files rather then just using pragma is a big difference.
it's only one line of code do you have any reason for not using it?? other then not liking it..
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question