C++: Error occurs when fmt library is included - c++

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?

Related

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

Installing the FFTW3 library on Windows 10 using Code::Blocks (C++)

I want to install the FFTW3 library in my system which runs on Windows 10. My compiler is the minGW GCC 10.1 and I am using Code::Blocks.
I have downloaded the 64bit version from http://www.fftw.org/install/windows.html and unzipped it in C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3.
Then I followed the steps described here https://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/. In step 4 it says "Tell the linker where to look for the library file(s) for the library."
Since there is no .lib file, it had to be created. I copied the libfftw3-3.def file and pasted it inside the bin folder of the mingw64 compiler, so that the dlltool can be used. Note that inside the same bin folder there exists the as.exe executable. I added this directory, namely C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin to system PATH as described in MinGW dlltool creates empty file.
Then I opened the cmd window as admin and executed dlltool -v -d nlib32.def -l nlib32.lib. The 2KB libfftw3-3.lib file was created inside the compiler's bin folder.
Then, again, I followed the steps that are described in the link I provided above. For convinience, I am posting the steps directly below.
Once per library:
Acquire the library. Download it from the website or via a package manager.
Install the library. Unzip it to a directory or install it via a package manager.
Tell the compiler where to look for the header file(s) for the library.
Here I set the path to be C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3
Tell the linker where to look for the library file(s) for the library.
Here I set the path to be C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin
Once per project:
Tell the linker which static or import library files to link.
Again the path was set to C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin
#include the library’s header file(s) in your program.
Make sure the program know where to find any dynamic libraries being used.
When I execute the following code
#include <iostream>
#include <fftw3.h>
int main(){
int N = 100;
fftw_complex *in;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
}
I am getting the following error: "Undefined reference to '__imp_fftw_malloc' ".
I don't know what I am doing wrong so that the compiler cannot find the function that I am calling, but I guess that the problem is in step 7, that is in the "Make sure the program know where to find any dynamic libraries being used." step. Note that this is the first time I had to deal with dynamic-link libraries etc so I am still confused.
I managed to make your code run in three simple steps (I suppose you have dowloaded and extracted FFTW properly and installed Code::Blocks too):
Indicate the FFTW directory so the header fftw3.h can be read. Build options > Search directories > Compiler and specify where the header file is. To me it's C:\Program Files\FFTW.
Copy the libfftw3-3.dll file from the FFTW directory to next to the .exe of your application. Tp me it's C:\projets\fftwEx\bin\Debug.
Copy and rename the libfftw3-3.dll file in the original installed directory to libfftw3-3.dll.a. Then indicate it's path in Build options > Linker settings > Link libraries. To me it's C:\Program Files\FFTW\libfftw3-3.dll.a.

Xcode External Build System Project Can't Find wchar.h

I'm trying to figure out how to use Xcode's "External Build System" project template to do some C++ coding. I've set it up with a very simple test project, just to make sure that I understand the configuration. I'm using make to build the project. When I try to run it, the build fails with the error message 'wchar.h' file not found.
Here are the steps I took to set up the project:
Create a new Project, using the Other -> External Build System template.
Set the Build Tool option to /usr/bin/make.
Copy my source file, ex_3_4.cpp to the directory where the Xcode project is located, and add it to the project using the Add files to "TestProject"... menu option.
Copy the makefile to the directory where the Xcode project is located.
Everything works if I run make from the terminal - I get an executable that runs fine, and there is no trouble finding wchar.h or any other headers. So I know that this is a problem with something in the project settings.
Here is the code in the source file:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!\n";
}
And here is my makefile:
all:
clang++ ex_3_4.cpp -o ex_3_4
clean:
rm ex_3_4
I can't find any place in the project settings where I can specify a search path for the wchar.h file (or any other header files for that matter), so I'm not sure how to fix this. I feel like it must be something simple.
If it makes any difference, I've been using Xcode 7.3, but I've also tried it with the new Xcode 8.0. I get the same error message using either version.
Perhaps you want to add a library target to your project, add it as a dependency on your project and then, your .h into the Headers section

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

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

Problem with installing Ogre sdk?

I'm new to Ogre and tried to run the first tutorial, but I have faced a problem getting the
error message
OGRE EXCEPTION(6:FileNotFoundException): 'resources_d.cfg' file not found! in
ConfigFile::load at ../../OgreMain/src/OgreConfigFile.cpp (line 83)
Please help, its critical!
Another question:
Is cmake important for installing the Ogre sdk?
After getting ogre compiled/installed using cmake
on linux those two config files live at
/usr/local/share/OGRE/resources.cfg
/usr/local/share/OGRE/plugins.cfg
just import both into your ogre project
Once ogre is installed, your project does not need cmake
To get you going for the tutorials :
How to setup eclipse with ogre :
File -> New -> C++ Project -> EmptyProject
C/C++ Build -> Environment
OGRE_LOC /home/scott/src/ogre_src_v1-7-3
C/C++ Build -> Settings
GCC C++ Compiler -> Includes
${OGRE_LOC}/OgreMain/include
/usr/local/include/OGRE
${OGRE_LOC}/Samples/Common/include
/usr/include/OIS
GCC C++ Linker -> Libraries (-l)
OgreMain
OgreTerrain
OIS
CEGUIOgreRenderer
right click project -> Properties -> Import
General -> File System ->
ONLY import those 4 files from the tutorial project
(NOT dist, build, makefiles ...)
BaseApplication.cpp
BaseApplication.h
TutorialApplication.cpp
TutorialApplication.h
also import these files :
/usr/local/share/OGRE/resources.cfg
/usr/local/share/OGRE/plugins.cfg
Now you are ready to compile and run !
To add an Ogre model :
First do above steps to create an ogre project, assure it compiles OK. On execution it'll render a black screen - thats fine. Now to add a model (an Ogre) simply edit TutorialApplication.cpp so function createScene appears as :
``
void TutorialApplication::createScene(void)
{
Ogre::Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
headNode->attachObject(ogreHead);
// Set ambient light
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
// Create a light
Ogre::Light* l = mSceneMgr->createLight("MainLight");
l->setPosition(20,80,50);
}
CMake is critical for building the ogre sdk from source - I would not try to configure the installation yourself. If you are using the prebuilt sdk, cmake is probably unnecessary.
As far as your error goes, it happens to be that you are trying to load resources from the resources.cfg. I am unaware of your operating system, however, be sure that your resources.cfg is in the same directory as your binary. If you are using MSVC and running it through the debugger, make sure your working directory (found in Project Properties -> Debugging -> Working Directory) is set to the directory of your executable.