Solved

connect Lib with another Lib

Posted on 2003-11-28
9
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

617 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