Solved

connect Lib with another Lib

Posted on 2003-11-28
9
377 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find boost header files using gnu make (MinGW) on Win 7 11 79
C++ - Convert a wString to char * 9 518
c++ syntax question 9 44
Header of docx file 17 98
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

863 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

24 Experts available now in Live!

Get 1:1 Help Now