How to find dependent libraries [duplicate] - c++

This question already has answers here:
How to show all shared libraries used by executables in Linux?
(14 answers)
Closed 9 years ago.
I got a C/C++ application, i need to determine all (shared) libraries on which it is dependent, so i can share it with other people along with libraries so they don't have to install any package, on Linux.
So is it possible to determine all libraries on which a C++ application is dependent?
A little clarification, i dont have application makefiles for the moment, thats why i have to find another way.

I think for linux you can use ldd command. You can see the man page for this command or also find this here http://linux.about.com/library/cmd/blcmdl1_ldd.htm.

Try to use ldd which will list the dependent libraries for that executable

Related

How C++ organize(manage) third-party lib? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
(I've just edited the question to be more specific)
I know that this question might be too general to answer, but I'm just can not find good tutorial on this, so trying to seek for help here.
I'm new to C++, previously my main programing language is Java and Python. The way that C++ manage third-party lib is somehow confusing for me......While Python can easily install things with pip, Java can import the JAR, how C++ organize those things?
I would like to split my question into few parts:
Here is some understanding and question of mine:
As long as the compiler, or IDE, know the path of the lib, then everything is fine. So when saying install, we just add the path of the lib to some system path. And for IDE, we just config the setting so that it can resolve the lib in given path. Correct me if anything is wrong.
Some C++ lib are all source code, and some contains sth. like .so or .dll, what is that? And what's the difference? I saw some lib saying that it can be used with simply include a few headers, but some require static linking, what does it mean?
What's is a general good approach to manage all those lib? (For example, in python, pip will simply install to some global scope, or we use vitrual env to manage that. Then anything similar to pip in C++?
More specifically, I'm using CLion, and Clion use CMake, so maybe all I suppose to do is config the CMakeList.text correctly and then the IDE will resolve all lib and compile correctly?
Again sorry for such general and somehow opaque question, but I'm totally lost as a newb for C++, which is much more complicated than Python and Java I used before.....
Any good tutorials might be of great help, thanks!
C++ doesn't. C++ is a language not a specific compiler or implementation.
With that said, for most compilers, building a C++ application is done in multiple steps:
Edit
Compile to object file
Link to executable.
The C++ compiler is technically only involved in step 2 (and really only part of step 2).
Most compilers and linkers since long ago allow you to put header- and library-file anywhere, and then there are flags passed to the compiler and linker on the command-line that tell the compiler and linker where to find the files.
For header files the (common) command-line option -I (upper-case i) is used to add a path to be searched for header files. For libraries the option -L similarly adds a path to be searched by the linker for libraries. There are of course default paths built into the compiler and linker, and the -I and -L options adds to those defaults.
Then to link with an actual library, the linker-option -l (lower-case L) is the common option to use. Each -l options list a single library that needs to be linked into the executable.
In regards to CMake and CLion, the CLion IDE doesn't really link anything at all. Instead it uses CMake to create a set of makefiles which contains the information used to build the targets.
Lastly there are some C and C++ alternatives to PIP or other languages package managers, but generally you use the standard way to install programs and libraries on your system.
Like on Windows you find an installer, and then modify your project settings (using CMake CMakeLists.txt, raw Makefile, or IDE settings) to add the directories needed.
For Linux systems you use the standard package manager (like apt on Debian-based systems, or yum on Fedora-based systems, etc.) to find and install libraries. Then the libraries and their header files will be installed in the default locations. You still need to set up the build-environment to actually link to the libraries.
The common way is, that you include the thirdparty stuff as a .dll or you can include it direct as code (as example boost ... you have to load it and to make it work you only have to include the parts you want, and for some parts from boost you have to build it with your compiler settings and include the .dlls)
The thing with the manager like you want I only now from VisualStudio with NuGet. I have no idea if is there such a thing for CLion.
As example you can look to the example from opencv:
https://docs.opencv.org/master/d3/d52/tutorial_windows_install.html
For your questions:
Correct. But in case the lib have to match also the settings (32/64 bit, release/debug)
If you only have to include some headers, then the code is direct included to your project and compiled with your code. If you have to link it as a binary (.dll windows, .so Unix (i think please correct me if wrong)) than the code is compiled and you link the compiled functions to your code.
Here a answer to .so:
What are .a and .so files?
And here for static and dynamic libs:
When to use dynamic vs. static libraries

Display frame from VNC/RFB into an OpenGL application [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 8 years ago.
I would like to be able to display remote client in a simple OpenGL application. "Simple" means only display the client such as a texture.
I started to look the VNC protocol but due to their popularity I only have few documentation related to VNCViewer. About RFB the only documentation is: http://www.realvnc.com/docs/rfbproto.pdf which is cool to understand the protocol but not enough to use it in a C++ OpenGL application. Then I found: http://libvnc.github.io/
I tried to compile the example (downloaded from github). So I added into my qtproject all rfb headers files run cmake on some of them. Then I built it but got the error:
undefined reference to `rfbMakeXCursor' and many others related to rfbXxxxx
rfb.h contains declarations to those "undefined" errors.
I don't understand what did I do wrong. Has anybody already made it work?
I'm working on Windows 8.1 64bit using C++ qtCreator and MinGW.
Headers are just ""able of contents" for the compiler to know, which functions can be called. You need to actually link to the library. The odds are, that since you've got it from GitHub you must first build the library. The built library you then add to some "extras/lib" directory in your project, configure that directory as additional library directory and add the library to the linker flags.

Where can I download the pthread.h, semophore.h and their libraries? [duplicate]

This question already has answers here:
Using pthread.h on a windows build
(3 answers)
Closed 9 years ago.
Where can I download the pthread.h, semophore.h and their libraries for C?
I need to download for windows. And also please give the linking procedure for VS2010.
Windows got its own threading mechanism and is not dependent on pthread etc, similarly it also got semaphores (http://msdn.microsoft.com/en-us/library/windows/desktop/ms686946(v=vs.85).aspx), but there are pthread port for windows http://sourceware.org/pthreads-win32/, you can give it a try.
Windows does not support pthread libray because windows it's not a POSIX system
The pthread is POSIX and it's available only for POSIX system like linux, BSD, Mac OS X etc... but not available for windows
You have to use portable pthread solution for windows instaed like the solution that Saqlain provide in his answer.
I did not advise to use the portable solution I advise to use the ways that your Operating system provide. And Windows has its own way to manage threads and semaphore
BTW: Using the POSIX pthread library is not by just include the header file pthread.h and semophore.h you have also to use the library (*.so or *.a) because it's needed in the linkage phase in your build.

Is it possible to extract a object file from a file.lib? [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
build a file.lib to a file.a usable on linux
As I say in the title is it possible to extract a object file from a file.lib. The point of this is to then create the file.a so I can compile the ported file.cpp I ported from windows to linux.
You can use lib /extract to invoke the librarian and extract object files out of a lib. However, note that you can't just pack Windows-generated object files into a .a archive and expect them to work on Linux. When porting across platforms, you have to recompile from source.

Moving from Windows to Ubuntu [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I used to program in Windows with Microsoft Visual C++ and I need to make some of my portable programs (written in portable C++) to be cross-platform, or at least I can release a working version of my program for both Linux and Windows.
I am total newcomer in Linux application development (and rarely use the OS itself).
So, today, I installed Ubuntu 10.04 LTS (through Wubi) and equipped Code::Blocks with the g++ compiler as my main weapon. Then I compiled my very first Hello World linux program, and I confused about the output program.
I can run my program through the "Build and Run" menu option in Code::Blocks, but when I tried to launch the compiled application externally through a File Browser (in /media/MyNTFSPartition/MyProject/bin/Release; yes, I saved it in my NTFS partition), the program didn't show up.
Why? I ran out of idea.
I need to change my Windows and Microsoft Visual Studio mindset to Linux and Code::Blocks mindset.
So I came up with these questions:
How can I execute my compiled linux programs externally (outside IDE)?
In Windows, I simply run the generated executable (.exe) file
How can I distribute my linux application?
In Windows, I simply distribute the executable files with the corresponding DLL files (if any)
What is the equivalent of LIBs (static library) and DLLs (dynamic library) in linux and how to use them?
In Windows/Visual Studio, I simply add the required libraries to the Additional Dependencies in the Project Settings, and my program will automatically link with the required static library(-ies)/DLLs.
Is it possible to use the "binary form" of a C++ library (if provided) so that I wouldn't need to recompile the entire library source code?
In Windows, yes. Sometimes precompiled *.lib files are provided.
If I want to create a wxWidgets application in Linux, which package should I pick for Ubuntu? wxGTK or wxX11? Can I run wxGTK program under X11?
In Windows, I use wxMSW, Of course.
If question no. 4 is answered possible, are precompiled wxX11/wxGTK library exists out there? Haven't tried deep google search.
In Windows, there is a project called "wxPack" (http://wxpack.sourceforge.net/) that saves a lot of my time.
Sorry for asking many questions, but I am really confused on these linux development fundamentals.
Any kind of help would be appreciated =)
Thanks.
How can I execute my compiled linux
programs externally (outside IDE)? In
Windows, I simply run the generated
executable (.exe) file
On Linux you do the same. The only difference is that on Linux the current directory is by default not in PATH, so typically you do:
./myapp
If you add current dir to the path
PATH=".:$PATH"
then windows-like way
myapp
will do, but this is not recommended due to security risks, at least in shared environments (you don't want to run /tmp/ls left by somebody).
How can I distribute my linux application?
In Windows, I simply distribute the executable files with the corresponding DLL files (if any)
If you are serious about distributing, you should probably learn about .deb (Ubuntu, Debian) and .rpm (RedHat, CentOS, SUSE). Those are "packages" which make it easy for the user to install the application using distribution-specific way.
There are also a few installer projects which work similarly to windows installer generators, but I recommend studying the former path first.
What is the equivalent of LIBs (static library) and DLLs (dynamic library) in linux and how to use them?
.a (static) and .so (dynamic). You use them in more or less the same way as on Windows, of course using gcc-specific compilation options. I don't use Code::Blocks so I don't know how their dialogs look like, in the end it is about adding -llibrary to the linking options (guess what: on windows it is about adding /llibrary ;-))
Is it possible to use the "binary form" of a C++ library (if provided) so that I wouldn't need to recompile the entire library source code?
Yes. And plenty of libraries are already present in distributions.
Note also that if you use .deb's and .rpm's for distribution, you can say "my app needs such and such libraries installed" and they will be installed from the distribution archives. And this is recommended way, in general you should NOT distribute your copy of the libraries.
If I want to create a wxWidgets application in Linux, which package should I pick for Ubuntu? wxGTK or wxX11? Can I run wxGTK program under X11?
Try wxGTK first, dialogs may look better, gnome themes should be used etc.
If question no. 4 is answered possible, are precompiled wxX11/wxGTK library exists out there? Haven't tried deep google search.
Try
apt-cache search wx
(or spawn your Ubuntu Software Center and search for wx)
In short: you will find everything you need in distribution archives.
Navigate to the folder with your compiled program and execute ./program
Send the program, plus any .so files
.a is static library, .so is shared libraries.
Yes, but often you need to compile it yourself first.
Not sure about wxWidgets distributions, though.
Since Ubuntu comes with wxGTK packages you should definitely build against them. For development you should use a debug version though, so it might be good to build yourself, but for deployment building against the packages the system provides seems better.
wxX11 is a worse choice than wxGTK, use it only for systems where wxGTK doesn't exist or requires newer GTK libraries than are available.
Why not just stick with what you know and develop in .NET? Ubuntu comes native with Mono. You could keep using Visual C++ or step up to C# and make your life a whole lot easier.
A piece of general advice to Linux newcomers, but who are technically minded to begin with, is: You should learn to use your chosen distribution properly.
In your case, that means learning how to acquire the right development packages provided by Ubuntu. For instance, some other people are advising you to download the source for libraries you are going to use, but the better way is to use Ubuntu's package system to download the libraries you want to program against, together with the headers for that library (often put in a separate package) as well as the debug symbols for the library (also often in a separate package).
Look in the System->Administration menu in Ubuntu for the Synaptic tool, which allows you to search the package repositories on the Internet. You'll almost certainly find packages for the libraries you need, as well as all tools.
1, Unix generally doesn't have a particular extension for an executable - so myprog.exe would just be myprog.
You might have to set it to be executable if the IDE doesn't do this automatically, type "chmod +x myprog"
5, For wxWindows I would download the source and build it, check the build instructions but it's probably just a matter of "configure;make;make install". Generally in Unix you build libs form source so that they can correctly find all the components on your machine - you also have the source of examples etc.
I just added some information to rlbond's answer.
It is depens on Linux version. If you use a Ubuntu - create a deb-package. (http://ubuntuforums.org/showthread.php?t=51003)
Can I run wxGTK program under X11?
Yes, if you have wxGTK package installed :)
This is not really going to answer your questions, but I think is a valid recommendation.
You have two issues you are trying to deal with:
The Linux environment.
Making sure your program is
portable.
If I were you I would load CodeBlocks on Windows and run against either Cygwin or Mingw, that will help you make sure your code is portable across platforms. You are familiar with the environment and would gain maximum productivity getting over the OS hurdle.
Once you are satisfied with the above then take your code and move it to Linux. At that point any porting effort should be trivial.
When you say your program didn't show up I assume you mean that it was there in the file browser but when you double clicked it you got a busy cursor for a moment and then nothing happened?
If so then it means that the program failed to run, probably because it couldn't find the dynamic libraries it's linked against. To diagnose the problem you can run it from a terminal and then you'll be told what the problem is.
You might want to read the manual page for ld.so i.e. type
man ld.so
into a terminal. This tells you where the Linux dynamic library linker looks for libraries at run-time. It also refers you to another useful tool called ldd which I recommend becoming familiar with if your are doing Linux development.