Solved

connect Lib with another Lib

Posted on 2003-11-28
9
381 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
Independent Software Vendors: 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!

 

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

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

761 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