Solved

connect Lib with another Lib

Posted on 2003-11-28
9
375 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now