•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,948 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,884 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1749 | Replies: 15 | Solved
![]() |
I have developed a set of libraries/common classes that I use in all my apps (this is on unix), and compiled them into a shared object (.so). Then, when I compile my individual apps, I link the library with the executable with -L /libs/ -l mylib . When running any app, I then make sure that the /libs directory is in my LD_LIBRARY_PATH
This works perfectly fine in most cases. The problem I'm facing is that I change these libraries often, and therefore for my existing applications stop working if they are not recompiled/re-linked against the new .so file.
Here's my question: (finally)
Is there a way that I can link in my library code (via compiler flags, etc.) such that the executable is 'stand-alone' meaning that all of the required code is there? This way, the apps can use the code that it was compiled with, without regard to if and when I change the library. I don't care if the executable size grows or anything like that - I've got the disk space.
This works perfectly fine in most cases. The problem I'm facing is that I change these libraries often, and therefore for my existing applications stop working if they are not recompiled/re-linked against the new .so file.
Here's my question: (finally)
Is there a way that I can link in my library code (via compiler flags, etc.) such that the executable is 'stand-alone' meaning that all of the required code is there? This way, the apps can use the code that it was compiled with, without regard to if and when I change the library. I don't care if the executable size grows or anything like that - I've got the disk space.
•
•
Join Date: May 2004
Posts: 177
Reputation:
Rep Power: 5
Solved Threads: 9
Yes. - it's called a static link. It means that all of the runtime you need is part of the image file - obviously a much bigger image file.
I can't tell which version of unix you have, but your man ld page will tell you how to do that. In most flavors of Unix you provide the cc command with a list of static libraries ".a" files including libc.a. You will also have to put your own runtime into one of these archives as well - or link against the objects in it. Again, the ld manpage is your friend.
I can't tell which version of unix you have, but your man ld page will tell you how to do that. In most flavors of Unix you provide the cc command with a list of static libraries ".a" files including libc.a. You will also have to put your own runtime into one of these archives as well - or link against the objects in it. Again, the ld manpage is your friend.
•
•
Join Date: May 2004
Posts: 177
Reputation:
Rep Power: 5
Solved Threads: 9
You're on the right track. I don't use Solaris, but I do know it has some (what I think are) funny conventions.
Now that I know it's Solaris, you can use versioning of your .so files, as long as you keep all the old ones out there. You can park all you stuff in a special area that won't get clobbered in an update, then define LD_LIBRARY_PATH (or SHRLIB_PATH) so that dld can open the libraries -if you plan to move them around later. Link specifically against a version like "-l mylib.3.2"
Now that I know it's Solaris, you can use versioning of your .so files, as long as you keep all the old ones out there. You can park all you stuff in a special area that won't get clobbered in an update, then define LD_LIBRARY_PATH (or SHRLIB_PATH) so that dld can open the libraries -if you plan to move them around later. Link specifically against a version like "-l mylib.3.2"
•
•
Join Date: May 2004
Posts: 177
Reputation:
Rep Power: 5
Solved Threads: 9
The "moving over" part is the reason for which static linking exists.
Your problem could be looked at another way: as an implementation/deployment issue.
Matching up correct code with correct run-times. If you are working for a company ask them to look at TeamTrack and ChangeMan from Serena. You can also package everything as one tarball and use cvs or whatever to manage your tarballs.
Your problem could be looked at another way: as an implementation/deployment issue.
Matching up correct code with correct run-times. If you are working for a company ask them to look at TeamTrack and ChangeMan from Serena. You can also package everything as one tarball and use cvs or whatever to manage your tarballs.
Yes, this is why I want to link statically. My problem now however seems to be that my template code cannot be linked statically. Is that a known issue? Does template code need to be linked dynamically? (Given that it determines the classes/types at runtime, it seems somewhat logical).. If that's the case, I may be stuck.
•
•
•
•
Does template code need to be linked dynamically?
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Linking two objectmodules OR Using 'Project' in VC++6.0 compiler? (C++)
- EASY question? checking for line feed (return) in a html file with C++ (C++)
- A question of RAM (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: After 2nd element read... cout is "scattered"
- Next Thread: question with files and fstream


Linear Mode