Configuring Netbeans to Debug a C++ program containing non standard libraries - c++

I want to use a non standard library ( igraph C library ) to build a 'hello world' program in C++, using Netbeans.
I want to use Debug features of Netbeans too.
First I followed the installation instructions provided by the library vendor, used a terminal to compile and run a hello world program supplied by library vendor. It compiles & runs fine using terminal.
The problem is as soon as I open the C project file in Netbeans, I must CONFIGURE it so that it can :
Run the program
Debug the program
Netbeans lets you run and debug C++ programs off the bat, if you using their standard libraries. But I read on some forums that some configuration needs to be done if I want to make Netbeans run and debug C++ programs containing non standard libraries

I found the answer. Here are the steps :
1. Find out where your non standard library files are installed
On my Ubuntu I used the following command to find out the location of my installed files :
pkg-config --libs --cflags igraph
In above command you have to substitute igraph with name of YOUR non standard library that you installed.
This command gave me following output :
-I/usr/local/include/igraph -L/usr/local/lib -ligraph
I noted down the path after -I, the path after -L and the string after -l. These 3 need to be fed inside Netbeans in the steps below
source: http://igraph.org/c/doc/igraph-tutorial.html#idm470953198960
2. Configure Netbeans
Right click on Project in Netbeans -> properties -> Linker ->Libraries -> Add option -> Other -> type -ligraph in here
In your case you have to type what you found instead of -ligraph on your system during step #1
Project -> properties -> Linker -> Additional Library Directories > I typed /usr/local/lib in here
In your case you have to use the path you got on your system after -L flag in step #1
Project -> properties -> C++ Compiler -> Include Directories -> I typed /usr/local/include/igraph in here
In your case you have to use the path you got on your system after -I flag in step #1
source: https://stackoverflow.com/a/13292276/3143538
add to the Project->Properties->Run->Environment :
Name: LD_LIBRARY_PATH
Value: $LD_LIBRARY_PATH:/usr/local/lib
instead of /usr/local/lib you have to use the path you got after -L flag in step #1
source: https://askubuntu.com/questions/267071/ld-library-path-specification
After above steps, I am able to both compile, run, and debug the program

Related

C++: Error occurs when fmt library is included

https://github.com/fmtlib/fmt
I'm having trouble using c++ library on ubuntu eclipse. I downloaded the fmt library from github. I followed the steps as described in the documentation section Building the Library. In fmt folder;
mkdir build # Create a directory to hold the build output.
cd build
cmake .. # Generate native build scripts.
After running the commands, makefiles are created in the build array.
To install the library I ran following command.
sudo make install
After the installation, the necessary files were copied to the /usr/local/ directory. I copied the header files and compiled libfmt.a file to my project directory.
My project hierarchy;
fmtTestProject
|--Debug
|--src
|--fmtTest.cpp
|--include
|--args.h
|--chrono.h
|--color.h
|--compile.h
|--core.h
|--format.h
|--format-inl.h
|--os.h
|--ostream.h
|--printf.h
|--ranges.h
|--std.h
|--xchar.h
|--lib
|--libfmt.a
I defined the include files to the eclipse project.
fmtTest -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Includes -> Include paths -> "${workspace_loc:/${ProjName}/include}"
fmtTest -> Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Library search path -> "${workspace_loc:/${ProjName}/lib}"
After the define libraries, I wrote the code in the documentation and compiled it.
#include <fmt/core.h>
int main() {
fmt::print("Hello, world!\n");
}
The code compiles without errors. But the problem is there are too many errors for core.h file. Some errors;
Type 'std::experimental::basic_string_view<Char>' could not be resolved
Invalid overload of 'parse_format_specs'
Return has value, in function returning void
There are errors like these. The software compiles and runs, but there are errors in both main and library files. Likewise, I did the same compiling and installing to use the library named spdlog. It also compiles and works, but a lot of errors occur. Am I missing something in the cmake processes? There are always errors when I import an external library. How can I solve it?

Failing to install gtkmm / gtk+

So i am new on the platform, i use c/c++ and i have interests in graph interfaces so i decided to use gtk+and gtkmm with visual studio.
First, i downloaded gtk for the gnome project. I followed all the steps and i got this after a manual run :
\\\ test23.cpp
#include <gtkmm.h>
int main(int argc, char* argv[])
{
Gtk::Main app(argc, argv);
Gtk::Window fenetre;
Gtk::Main::run(fenetre);
return 0;
}
$ g++ -std=c++ test23.cpp $(pkg-config gtkmm-3.0 --cflags --libs | sed 's/ -I/ -isystem /g')
Package gtkmm-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtkmm-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtkmm-3.0' found
bash: g++: command not found
so i decided to install using vcpkg.
But I failed to install gtk+ and gtkmm after multiple tries.
Here what i've got :
C:\WINDOWS\system32>vcpkg install gtk
Computing installation plan...
The following packages will be built and installed:
gtk[core]:x86-windows
* harfbuzz[core,glib]:x86-windows
* libepoxy[core]:x86-windows
* pango[core]:x86-windows
Additional packages (*) will be modified to complete this operation.
Detecting compiler hash for triplet x86-windows...
Starting package 1/4: libepoxy:x86-windows
Building package libepoxy[core]:x86-windows...
Could not locate cached archive: C:\Users\Manolo97233\AppData\Local\vcpkg\archives\f7\f743ec00b235ca7fd37812284b7d2e09d89b368a.zip
-- Using cached C:/Windows/SysWOW64/vcpkg/downloads/anholt-libepoxy-1.5.4.tar.gz
-- Cleaning sources at C:/Windows/SysWOW64/vcpkg/buildtrees/libepoxy/src/1.5.4-337c486045.clean. Use --editable to skip cleaning for the packages you specify.
-- Extracting source C:/Windows/SysWOW64/vcpkg/downloads/anholt-libepoxy-1.5.4.tar.gz
-- Applying patch libepoxy-1.5.4_Add_call_convention_to_mock_function.patch
-- Using source at C:/Windows/SysWOW64/vcpkg/buildtrees/libepoxy/src/1.5.4-337c486045.clean
-- Acquiring MSYS Packages...
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:72 (message):
Command failed: C:/Windows/SysWOW64/vcpkg/downloads/tools/msys2/msys64/usr/bin/bash.exe --noprofile --norc -c "pacman -S --noconfirm --needed pkg-config"
Working Directory: C:/Windows/SysWOW64/vcpkg/downloads/tools/msys2
Error code: 1
See logs for more information:
C:\Windows\SysWOW64\vcpkg\buildtrees\libepoxy\msys-pacman-x86-windows-err.log
Call Stack (most recent call first):
scripts/cmake/vcpkg_acquire_msys.cmake:127 (vcpkg_execute_required_process)
scripts/cmake/vcpkg_configure_meson.cmake:106 (vcpkg_acquire_msys)
ports/libepoxy/portfile.cmake:16 (vcpkg_configure_meson)
scripts/ports.cmake:79 (include)
I believed i had a problem with msys2 so i tried to install it separately following an install kit unsuccessfully.
then i tried to run separately other packages involved with gtkmm like pango and i got this :
//vcpkg install pango
Computing installation plan...
error writing file: C:\Windows\SysWOW64\vcpkg\buildtrees\0.vcpkg_dep_info.cmake: The data is invalid.
Someone explained on a topic it could be an vcpkg accessibility problem for others packages. i modified the accessibility of vcpkg for other packages in my systWOW64'file parameters but it went unsuccessful.
I don't know if vcpkg is problem because i did not remove it and re install it.
I am looking for solutions/options, I am short on ideas, i literally need some help.
Thanks
Use JHbuild, its your friend when building GNOME applications from source !
Run jhbuild build gtkmm --nodeps, the built files will be installed in $HOME/jhbuild/build. To compile your application with it, you must export the environment variable PKG_CONFIG_PATH as follows:
export PKG_CONFIG_PATH="$HOME/jhbuild/build/lib/pkgconfig"
(in the terminal you are running the g++ command from)
And you have to install g++.
I do not know how you are using bash together with visual studio, but
if you have apt, you can install g++ and gtkmm with the following command :
apt install libgtkmm-3.0-dev libgstreamermm-1.0-dev g++
If you have already downloaded gtk, then the downloaded package must contain a .pc file. The directory this file is in when you installed the downloaded package you must add to the PKG_CONFIG_PATH.
Thanks Frederic for your answer it really help me.
I have got an other question. In my quest to add external packages to my C/C++ project, i read differents topics about how to convert static library (.a) into static library (.lib).
I downloaded packages and i wanted to add them manually using their pathway.
I added my packages as followed:
1 / Add the path of the headers in the compiler directories for the project:
-> Project / Properties menu
-> On the left tree, choose Configuration properties - C / C ++ - General
-> On the right table, the first line "Other Include directories": add the directory (s) of your library containing the headers
2 / Add the path of the .lib in the compiler directories for the project:
-> Project / Properties menu
-> On the left tree, choose Configuration Properties - Link Editor - General
-> On the right table, the line "Directory of additional libraries": add the directory (s) of your library containing the .libs
3 / Specify the libraries with which your project is linked:
-> Project / Properties menu
-> On the left tree, choose Configuration Properties - Link Editor - Enter
-> On the right table, the first line "Additional dependencies": add the .lib library (s) with which your project must be linked
But I looked for .lib files to add to my linker input instead, I found .a files and .dll files and I didn't know what to do. . a files and .lib files are almost identical. It seems like .a files are used under linux while .lib are used under windows.
I tried to add the .a files unsuccesfilly. I wondered if I could convert an .a file into a .lib file.
Thanks

How to create a cross-platform C++ application in Netbeans?

I am experiencing some difficulties while creating a simple "Hello world" cross-platform C++ app in Netbeans 8.0.1 for both Linux and Windows operating systems. I found very few instructions for Windows and none for Linux (my OS is Ubuntu 14.04).
My research over the Internet brought me to a conclusion that there should be created one more makefile for Windows OS. Usually, while creating a C++ project Netbeans kindly proposes us to create a makefile for us. And it's great, but it's just for Linux.
I stuck on Makefile creation (never done this before manually), so these were my steps to creating makefile for Windows:
Right Click on Project -> New -> Makefile
File Name: "Makefile-Windows" -> Next
Compiler: GNU Compilers, Platform: Windows -> Next
Base Directory: Project directory -> Next
Target Name: hello-world ( "Executable" radio button ) -> Add -> Next
Directory for All created files: GNU-amd64-Windows -> Next
Enter source files: main.cpp -> Next
Directories to Search for Include Files: Left empty -> Next
Choose libraries to link with: None, Link mode: Dynamic Linking -> Next
Libraries to link with: Left empty -> Next
How would you like your code to be built?: Dev. mode -> Next
, 13. Compiler options: Left default -> Finish
As a result, after making this fresh baked makefile in my GNU-amd64-Windows folder appears an object file (main.o) and an executable file (hello-world), but still executable only in Linux. When I try to run it in Windows command line, I get the error:
"Bad Command or file name"
Just in case here is my main.cpp content:
#include <iostream>
int main( int argc, char** argv )
{
std::cout << "Hello world" << std::endl;
return 0;
}
If I have chosen a wrong way, then how should it be done?
As mentioned Borgleader, only C++ code can be cross-platform. Here is my solution:
Firstly, we shouldn't use Linux GCC compiler for compiling Windows applications. That's why we need to install Windows compiler for Linux:
sudo apt-get install mingw32 mingw32-binutils mingw32-runtime
Secondly, while creating makefile we should specify alternative compiler. Use:
/usr/bin/i586-mingw32msvc-g++
insteat of default:
g++
Finally, after making this makefile our output file becomes executable on Windows platforms.

how to add oracle oci libraries to C++ eclipse

I'm writing a method for Oracle in C++. I’m using the OCI library with Eclipse as my IDE. The code compiled completely but I’m getting this runtime error:
"error while loading shared libraries: libocci.so.11.1: cannot open shared object file: No such file or directory "
I included occi and clntsh and nnz11 through properties > c/c++ general /Path and symbols > libraries
I don't know how to fix this error, please help thanks you
IDE wont take like libocci.so.11.1
you have to convert into like libocci.so
ln -s libocci.so.11.1
then it will be renamed to libocci.so
then compile the code
Your compiler finds the libraries because your project probably specifies where to look for libs (-L flag on the linker command line). But the runtime linker needs to find the libs as well.
I assume you're running it on linux. You have 2 options:
A temporary solution is to define in your environment LD_LIBRARY_PATH=full path to dir where libocci.so* is installed. I'm not very familiar with eclipse, but there's likely a setting to change the runtime environment. You could also set LD_LIBRARY_PATH and then run ecplise in that env.
$ export LD_LIBRARY_PATH=...
$ command to run eclipse
A permanent solution is to add the full path to the dir. where the libs are to the file /etc/ld.so.conf, or better: create a file /etc/ld.so.conf.d/oracle and put the path in that file, nothing else. Then, as root, run ldconfig.
wow . finally i did it , by one variable and put it into .bashrc
1- export LD_LIBRARY_PATH=/opt/oracle/instantclient "The Path of libraries" and then
2- root#user:~# vi .bashrc "Make sure you are in root"
3- LD_LIBRARY_PATH=/opt/oracle/instantclient/ "Add this two lines into file"
export LD_LIBRARY_PATH
:)

With Eclipse: How to add include paths and libraries for all your C/C++ project

Is it possible to add include paths and libraries to all C/C++ projects? In others words: How can I make them global or copy one C/C++ project build setting to another one?
For Eclipse Indigo:
There is no possibility to define globally include paths and libraries.
But you can export and import them from one project to another.
Go to Project > Properties > C/C++ General > Paths and Symbols
Then click Export Settings... to save the include paths and/or symbol definitions to a file. In your other project, you can then use Import Settings...
Yes, you can, in 2 steps, more user-friendly as the one mentioned by parvus. Both are done in "Project Properties" -> "C/C++ General" -> "Paths and Symbols":
In an existing project where you've already configured the include paths: Highlight the include paths (in the tab "Includes") which you want to copy to the new project and choose "Export". Note that this adds an [Exp] tag to each line.
In the new created project: In the "References" tab, tick the checkbox of the just mentioned project and when you switch back to the "Includes" tab, you see that all the paths you've just exported appear there.
Referencing the libraries works the same way.
Also have a look at:
the Eclipse Juno Documentation to this topic,
a related StackOverflow question
I often use the CPATH environment variable to include different directories across all my projects. It's found under: c/c++->build->environment.
Be sure to separate each path with a ':' character (not a ';' semicolon).
You can also use PATH to include static libs. However, for me it's only worked reliably in linux. In OSX it ruins make.
The alternative would be to add these libraries and headers to your environments default search paths; place likes /usr/local/lib. Read up on where your linker searches by default.
For libraries I do the following in the source project:
Project -> properties -> c/c++Build -> c++ linker -> libraries
After this I select libraries (shift + mouse) & copy (ctrl + c)
In the blank project:
Project -> properties -> c/c++Build -> c++ linker -> libraries
ctrl + v (paste)
Works fine with eclipse juno
I just copy one project from using eclipse built in Project explorer. Afterwards, just rename source files.
I am looking into it long ago.
A few posts mentioned one method:
Project > Properties > C/C++ General > Paths and Symbols Then click Export Settings..
But it only works for including header files.
To specify libraries and library paths, as far as I know, I do not find an easy solution.
For example, I am now using ffmpeg libraries.
If you use "Makefile", the including and library files can be expressed below:
FFMPEG_LIBS= libavdevice
libavformat
libavfilter
libavcodec
libswresample
libswscale
libavutil
CFLAGS := $(shell pkg-config --cflags $(FFMPEG_LIBS)) $(CFLAGS) LDLIBS
:= $(shell pkg-config --libs $(FFMPEG_LIBS)) $(LDLIBS)
There are many files here.
If I include them one by one in an Eclipse C++ project, it is daunting.
I do not know why there is no option in Eclipse that we could include library files by using past a long line using ; as a separator, such as:
-lavdevice -lavfilter -lswresample -lswscale -lavformat -lavcodec -ldl -lasound -lSDL -lz -lrt -lavutil -lm
Is there any such way, or I have to type the library files one by one, or have to use Makefile?
I faced the same problem and solved it like this :
I saw that in the auto-generated makefile there are lines:
-include ../makefile.init
...
-include ../makefile.defs
...
-include ../makefile.targets
after reading How can I parameterize an Eclipse generated make file I realized that you can define variables outside of you project. That mean it can be shared variable to several projects. So I added makefile.defs file outside of the project and declare in it some variables:
MY_INCLUDE = <path to include>...
MY_LIBS_PATH = <path to libs>...
MY_LIBS = -lmylib ... (the libs)
than in all my projects "properties->c/c++ build->build variables" I defined new variable:
my_include = $(MY_INCLUDE)
my_libs_path = $(MYLIBS_PATH)
my_libs = $(MY_LIBS)
And than you can you those variables in the projects. Go to properties->c/c++ build->Settings and choose compiler includes and add $(my_include). Go to linker and choose Libraries and add to search path $(my_libs_path). For some reason the Libraries (-l) can't take my defined env variable so I bypass it by choosing linker and than go to Miscellaneous and add to linker flags $(my_libs). Finally you have to change the order in the command line (when the linker execute) cause the list of libs need to come after the .o files. So to do that you go to linker and tab and there you can see the final command line that is going to be executed. In "expert settings command line pattern" you move the ${FLAGS} to the back of the command line (that moves the $(my_libs) string to be in the back of the command line). THAT ALL. its a lot but you need to do it only once... hope that it helps someone...
Semi-automagically, it can be done using this perl script:
#!/usr/bin/perl
# pipe the (gcc) compile command into this script
# It emits listOptionValue lines to paste into .cproject
#
# To easily find the paste location, set the include path as usual to a string
# that is easily recognizable in the .cproject, e.g. to "MARKER_INCLUDE_PATH".
#
# Make sure eclipse is not running while you do these sorts of hacks and backup
# your .cproject before.
# -----------------------------------------------------------------------------------------
# sample line: <listOptionValue builtIn="false" value="/usr/include/gdk-pixbuf-2.0"/>
while (<>) {
#include_options = m#-I *(.*?) #g;
print join ("\n", #include_options) . "\n";
print join ('"/>' ."\n" . ' <listOptionValue builtIn="false" value="', #include_options);
print '"/>' . "\n";
}