Debugging C++ lib with eclipse - c++

I am working on project in Linux which involves
1) Static Lib in C++
2) GUI developed in C++/QT which uses static lib.
Now both the lib and gui are build from command prompt using makefiles.
I am trying to debug both like when I hit one button, call should go from GUI to lib.
Is it possible to do like this in Linux with eclipse?
I can easily follow same debugging procedure in Windows using Visual studio and attaching lib to GUI but I cannot find any good way to do here with eclipse.
I have tried many IDEs/debuggers like
Anjuta
Code Blocks.
DDD,Kdbg
but none is working properly.
I am not sure that if I am wrong or is it much complex to debug?
Can some one suggest one proper way to debug ?

There shouldn't be any problem with debugging a static library as the relevant portions of it will be built in to the binary that you are debugging. If you are having problems then some things to check are that both the library and the binary are built with debugging information (usually the option -g to the compiler on linux) and that your debugger has access to the source code to the library.
Can you be any more specific about how debugging isn't working? It sounds like 'stepping in' to a library function isn't working as you are expecting it to.

Well I figured it out..
I am currently using Kdevelop..
With Kdevelp we can create QT project as well as c++(lib) project.
And there is option to attach process also.
So I can step through lib code by attaching GUI .

I created new project in eclipse and added existing source folder .
It then automatically adds all source files. Project has its own custom makefile . Now when I try to Debug the project , it shows me Debug window where I selected C/C++ Attach to Local application because I want to attach lib to GUI.
It asks me to enter project name in Debug window.
In Windows with visual studio it gives list of processes that can be attached, but here am I supposed to create project ?
I dont understand this..

Related

Bad Image error when trying to run program

So I recently finished a VC++ console application I have been working on and I sent it to one of my friends to try out but he cant even open it because he keeps getting an error.
A box will open up with the title Bad - Image and then it shows the error and stuff, it says it cant find the file MSVCP140D.dll on my friends computer but when I start the program it runs fine.
Can anyone tell me why he cant play the program and how to fix it?
You have built your project in debug mode and you are using Multi-threaded Debug DLL (/MDd) RunTime library.
In Visual Studio main menu, select Project -> Properties
Go to "Configuration Properties" -> C/C++ -> Code Generation
In Runtime Library, select Multi-threaded Debug (/MTd) and rebuild your project.
Alternatively you can build your project in Release mode, then select Multi-threaded (/MT) Runtime library.
This will make a stand-alone executable file which uses standard windows libraries, you won't have to provide additional dlls with the *.exe file.
You need to ship your program with the Microsoft Visual C++ Redistributable package. That's MSVCP140D.dll.
As user4581301 pointed out, the D in MSVCP140D.dll means 'Debug'.
You shouldn't ship a debug-enabled executable. It makes reverse engineering, hacking, and other modifications easier.
You should instead compile a release build, and ship it with the redistributable.
Well you need to do one thing(the easy solution), you just go to your system32 directory at system where you have built the code and find out the file MSVCP140D.dll, put it with your executable(.exe) and give it to your friend, and tell him to keep the dll in same folder as the exe.
MSVCP140D.dll (redistributable pack) is one of the run time dependencies you need to provide to run your application.
Now it will get installed. Or you can copy the dll at system32 at target system and then try.
But you shouldn't provide the debug build if you are giving it to client, you should provide the release version of it.

A matching Debug configuration cannot be found in the wxWidgets directory you specified.

I have tried to setup and create wxWidgets project using wxWindgets installer and code::block-mingw installations.
When I am trying to create a wx-widgets smith project, I have below problem
A matching Debug configuration cannot be found in the wxWidgets directory you specified.
This means Debug target of your project will not build
Are you sure you want to continue with these settings ?
does anybody have any idea about this and what is the recommended way to setup wxWidgets and code-block in Windows ?
Did you compile your wxWidgets as a debug build? I got the same error, because I only buitl wxWidgets as a release build. However, I didn't intend to use the debug build anyway, because I didn't want to debug it, just use it. So you can continue with your project and then you have to replace the library names with the correct ones. Mostly this means removing the d at the end of the library name.
If you want to use a debug build, you have to build wxWidgets as a debug as well.
To fix the library names, you'd have to right-click on your project and go to "Build options... -> Linker settings".
Update
To compile it using MingW you have to follow this guide.
You may also have to adjust the include paths in your build options:
D:\src\c\wxWidgets_3.0.0\lib\gcc_lib\msw
D:\src\c\wxWidgets_3.0.0\include
And for the linker:
D:\src\c\wxWidgets_3.0.0\lib\gcc_lib
Problem is solved by following the exact instruction provided in Compiling wxWidgets 3.0.0 to develop Code::Blocks (MSW) section. I couldn't build wxWidgets correctly in windows. After I build wxWidget the same alert message mentioned in the question was popped when creating wxWidgets project using Code::Block but I dismissed and continue to create the project. This time it was worked.

Using a DLL with unmanaged code in Visual Studio 2010?

I'm fairly new to C++ and an trying to figure out to use the TagLib library for a project I am working on. I'm working with unmanaged C++ in Visual Studio 2010 on Windows 7 64bit. I've never used an external library before so I'm very confused on how to go about this.
From this blog entry I got the libtaglib.a and taglib.dll files. I ran across this SO question on how to use TagLib, but it deals with QT Creator, not Visual Studio and I'm not knowledgeable enough about the subject to understand what is being said to translate it into what needs done for Visual Studio.
So, some questions:
Is it even possible to do this with unmanaged code?
What exactly is the function of a .a file?
Most importantly, how do I go about using the taglib.dll in my program??
I've been all over Google looking for a way to do this, but my major problem is that everything I run across is over my head. Please let me know if more info is required. Any help is very much appreciated! Thanks!
I seem to have gotten it working successfully. Here's a rough outline of what I did:
1.) I used CMake to generate the Visual Studio solution.
2.) I attempted to build the tag project in the VS solution, but it failed.
3.) I made the corrections to a few source files as outlined here: http://old.nabble.com/taglib-fails-to-compile-with-MS-VC%2B%2B-2010-td29185593.html
4.) I built the tag project again in release mode. This time it was successful.
5.) I copied the resulting dll, def, and lib files to the same directory as the source files for my project.
6.) I copied the header files from the taglib source to a subdirectory in my project (not sure if this entirely good practice)
7.) In my project settings, I set the subdirectory with the header files as an additional include directory.
8.) I added the dll, exp, and lib files to my project by just going to Add>Existing Item.
9.) I added some code from the taglib examples and built it. Everything worked so I think I got it.
One caveat I ran into, since the DLL was built in release mode, my project had to be run in release mode or it would crash. I'm guessing that if I replaced the DLL with one built in debug mode I could run my program in debug mode, but I have not tried this.
You cannot use libraries specific to GCC (you can tell because they have .a extensions) with Visual Studio. You will have to build the library from source in order to use it with MSVC. Once you have done that it's a simple matter of adding the .lib generated from the build process to your project and things should work out of the box. (Note that it's a .lib you need whether you're compiling for dynamic linking or not -- doesn't matter in msvc land)
EDIT -- after looking at TagLib itself --
In order to compile TagLib you'll need to get the CMake build system, and TagLib itself, and have CMake build you a visual studio solution. Using that solution you'll be able to build the .libs and .dlls you need. Note that because TagLib is a KDE library, you'll probably need to also build some QT bits in order for everything work work successfully. However, I don't have specific experience with the library so I'm not going to be all that helpful here.
Yo do not have to recompile the source (to create the .lib file) if you have the .dll file. With dumpbin /exports and lib (both came with Visual Studio) yo can create a lib that you can link with your application. In this link you can see a nice explanation: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/
But as Billy Said, probably you would need other parts of QT to use this library.

C++ eclipse building error

I'm programming with Galileo on Ubuntu.
My project is compiled through the terminal fine. But for the nice features of eclipse I decided to use eclipse. So I copied and pasted everything inside an eclipse project directory. Then I refreshed the project in the project explorer and everything was found by eclipse. (EDITED) But a red mark (the error mark) is shown on the project icon and when I build the project no binary file is created.
And the last thing is that all the files inside the project have no errors!
what's the problem?
Presumably it is a makefile project. Have you set up the Eclipse IDE to use make with the correct make arguments?
Have you set up the path for the include and lib directories that you need?
Right click on the project in the tree viewer and bring up the preferences dialog and make sure.
There is a console output tab on the Eclipse IDE. What does that say?
There is also a Problems tab that sorts the compiler output. What is on this?
There could well be a problem with building it a a whole project, maybe a link error? More likely it has not been set up properly for eclipse.
Are you using helios? Autotools?

visual studio 2008 isn't creating an .exe file when i build my project. any ideas why?

i'm new to visual studio and couldn't find anything on google about this. i know this is an extremely noobish question, but i can't seem to find any info for it.
the debug shows me whatever i write, and the build has no errors, so i know the code i'm writing is fine.
the release folder doesn't contain the .exe, even after i build it, rebuild, clean, etc.
it's a win 32 console project. the release folder contains the .obj files, the manifest, the build log, idb, pch and pdb files (one of each)
Some possible reasons:
Did you accidentally create a class library project? In that case the output would be a DLL and not an EXE.
Does the output window or the error list display any build errors? In that case you should first fix these, then build again.
Did you change the configuration of the project, so that the output (EXE) is created in a different folder than the default one?
There's not a whole lot of reason for people to be guessing... You said you can find the build log - the exact location of any output file will be in there. To make sure you're seeing the right build log file, the output window in VS will have a link to the file that particular build run created:
1>Build log was saved at "file://c:\DevTrees\cppTest\Debug\BuildLog.htm"
1>cppTest - 0 error(s), 2 warning(s)
If you're having trouble interpreting it, post the contents.
I had the same problem; the advice above to look closely at the output window was just what I needed - thanks. My confusion was because I was looking in solution>project>Debug when VS put it in solution>Debug.
The Release and Debug folders contain outputs from different build configurations.
If you look in Project properties, you will see an Output Folder setting in the Build section, and it will be different for each configuration. (You can see the setting for each configuration using the dropdown list at the top of the Project Properties window)
The Release folder will only get populated when you build the project in the Release configuration.
To switch to the Release configuration, use the dropdown list in the toolbar.
EDIT: I am describing the UI for C# projects. It may be different for native code.
Are you sure that your project type is correct? A class library project won't build an executable. It would need to be some sort of application project to create an executable.
I had the same problem. The compilation went fine, but no .exe was generated in the target folder (.\Debug).
The problem was actually that the file containing the main() function was called "FooProject.cpp". I renamed it to "main.cpp" and then the .exe was generated properly.
In other IDEs such as Eclipse CDT, you don't need to have your main file called "main.cpp" as long as you have a proper main() function. This is apparently not the case for Visual C++.