Build with libpqxx in C++11 on Kdevelop - c++11

I'm trying to build a C++ program, that needs lipqxx functionalities. I'm on Ubuntu and I'm trying to use Kdevelop.
I did it successfully with Code::Blocks, but I'm trying to find a better IDE.
Now, what I've done with Kdevelop.
I created a simple example:
#include <pqxx/pqxx>
int main(int argc, char **argv) {
pqxx::connection c("dbname=xx host=localhost user=xx password=xx");
return 0;
}
I modified the CmakeList.txt to include the pqxx directory and to link with libpqxx.so:
cmake_minimum_required(VERSION 2.6)
project(testkdev)
include_directories ("/usr/include/pqxx")
LINK_DIRECTORIES("/usr/lib")
add_executable(testkdev main.cpp)
TARGET_LINK_LIBRARIES(testkdev libpqxx.so)
install(TARGETS testkdev RUNTIME DESTINATION bin)
At this point, the build process works.
But I need to do something else, I want to work in C++11.
So I add a -std=c++11 option, right clicking on my project, Open Configuration > Cmake > Advanced Values > CMAKE_CXX_FLAGS.
And I get the following errors:
/home/francis/projects/testKDEV/build> make -j2
[100%] Building CXX object CMakeFiles/testkdev.dir/main.cpp.o
In file included from /usr/include/c++/4.9/memory:79:0,
from /usr/include/c++/4.9/tr1/memory:39,
from /usr/include/pqxx/util.hxx:31,
from /usr/include/pqxx/util:18,
from /usr/include/pqxx/except.hxx:27,
from /usr/include/pqxx/except:19,
from /usr/include/pqxx/result.hxx:33,
from /usr/include/pqxx/result:19,
from /usr/include/pqxx/binarystring.hxx:26,
from /usr/include/pqxx/binarystring:18,
from /usr/include/pqxx/pqxx:17,
from /home/francis/projects/testKDEV/main.cpp:2:
/usr/include/c++/4.9/functional:1034:20: error: expected template-name before ‘<’ token
: tuple_element<__i, _Tuple> { };
^
/usr/include/c++/4.9/functional:1034:20: error: expected ‘{’ before ‘<’ token
/usr/include/c++/4.9/functional:1034:20: error: expected unqualified-id before ‘<’ token
/usr/include/c++/4.9/functional:1054:17: error: ‘tuple_size’ was not declared in this scope
(__i < tuple_size<_Tuple>::value)>
^
/usr/include/c++/4.9/functional:1054:35: error: ‘::value’ has not been declared
(__i < tuple_size<_Tuple>::value)>
and it goes on and on with errors...
Could anybody please help me understanding what I'm doing wrong ?

I don't know Kdevelop but I had similar problem. I use Eclipse. There is my question and answer. That is in Polish, so find someone, who can translate that. My English isn't too good but I'm going to transtalte as well as I can.
My question (forum.dobreprogramy.pl)
You need libpqxx-4.0.1. Download these packages:
md5sum
libpqxx-4.0.1
Next:
check package: md5sum -c libpqxx-4.0.1.tar.gz.md5sum
If it's ok: tar -xzvf libpqxx-4.0.1.tar.gz
cd libpqxx-4.0.1
./configure --prefix=/usr/local --enable-shared
You can choose path other than "/usr/local". There will be installed libpqxx.
make clean
make
make install
Now you should have header files in /usr/local/include and libpqxx.a, libpqxx.so in /usr/local/lib. If everything is ok, link libraries in IDE. I don't know, how to do this in your IDE but this is generally the same but properties are in different places. For example in Eclipse CDT:
In Project/properties/C\C++ Buid/Settings/GCC C++ Compiler/Includes/include paths type: /usr/local/include
In GCC C++ Linker/Libraries/Library search path type: /usr/local/lib
In GCC C++ Linker/Libraries/Libraries type: pqxx
In project: #include
Now try to compile. If it's ok, try to run program. If you have problem like in post #15
error while loading shared libraries: libpqxx-4.0.so: cannot open shared object file: No such file or directory
Go to /etc/ld.so.conf.d/ and make there new file named libpqxx-4.0.1.conf next open the file nad type there /usr/local/lib
After that issue the command ldconfig
In my case it was everything to connect with PostgreSQL using libpqxx and C++11. Good luck.

Related

FindGLEW.cmake No Rule To Make Target Error [SOLVED]

I am trying to build a very simple 'hello triangle' OpenGL application using CMake. I want to use find_package(GLEW) and the resulting imported target to link with Glew. When I run the make command, I am getting a 'No rule to make target' error.
According to the CMake documentation
https://cmake.org/cmake/help/latest/module/FindGLEW.html
https://cmake.org/cmake/help/latest/command/find_package.html
I can use find_package(GLEW) to return a target GLEW::GLEW which I will be able to use to link the Glew library to my code. When I run cmake .. everything builds and it reports that the glew-config.cmake file has been found.
-- Found GLEW: /usr/local/lib/cmake/glew/glew-config.cmake
I then run make and receive this error
$ make
Scanning dependencies of target test
[ 50%] Building CXX object CMakeFiles/test.dir/main.cpp.o
make[2]: *** No rule to make target `/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework', needed by `test'. Stop.'
I am running Mojave 10.14 and used homebrew to install cmake and glew which are both up to date. The path returned in the error above does not exist and I don't know where it is coming from.
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(test)
find_package(GLEW REQUIRED)
add_executable(test main.cpp)
target_link_libraries(test GLEW::GLEW)
Here is my source code:
#include <GL/glew.h>
#include <iostream>
int main(int argc, char **argv){
std::cout << "Glew Test" << std::endl;
}
As you can see it is the bare minimum code needed to simply link Glew.
The problem seems to be similar to this question:
CMake FIND_PACKAGE succeeds but returns wrong path
However, in that case there was a solution using a command line flag specific to Boost. The only reference I have found regarding FindGLEW and problems with macOS is here:
https://gitlab.kitware.com/cmake/cmake/issues/19542
But that seems to have been resolved.
The problem I am having seems to be this path that FindGLEW.cmake is returning:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework
I have looked in the actual FindGLEW.cmake file to see if I could find the source of this path but I'm not an expert with CMake so got lost pretty quickly. How could I find the origin of this path? Are there any CMake flags or variables I can set to work around this similar to the Boost question above?
I have successfully linked with Glew using this CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(test)
find_library(GLEW_DYLIB GLEW "/usr/local/Cellar/glew/2.1.0/lib")
if(NOT GLEW_DYLIB)
message(FATAL_ERROR "Glew not found")
endif()
add_library(Glew_target SHARED IMPORTED)
set_property(TARGET Glew_target PROPERTY IMPORTED_LOCATION "/usr/local/Cellar/glew/2.1.0/lib/libGLEW.dylib")
set_property(TARGET Glew_target PROPERTY IMPORTED_IMPLIB ${GLEW_DYLIB})
include_directories(
"/usr/local/Cellar/glew/2.1.0/include/"
)
add_executable(test main.cpp)
target_link_libraries(test Glew_target)
However, I would prefer to keep things as simple as possible with find_package() as that is definitely the cleaner method.
EDIT: SOLVED - see Tsyvarev's comment below clarifying the nature of the glew-config file that CMake was finding above. I removed this file and rebuilt the project with no problems.

Yocto meta-toolchain fatal error: stdio.h: No such file or directory

Question: How to add the standard library to arm-fslc-linux-gnueabi-gcc
Background:
I just had bitbake compile the meta-toolchain in the Yocto project.
I then installed the resulting SDK-toolchain
$
./build/tmp/deploy/sdk/fslc-framebuffer-glibc-x86_64-meta-toolchain-armv7at2hf-neon-toolchain-2.4.2.sh
which then installed the SDK-toolchain in /opt/fslc-framebuffer/2.4.2/
I can then easily run the executable to source the correct environment variables.
$
./opt/fslc-framebuffer/2.4.2/environment-setup-armv7at2hf-neon-fslc-linux-gnueabi
I now have access to the cross-compiler arm-fslc-linux-gnueabi-gcc
So far so good...
I then downloaded the barebone SDK from NXP here.
It's a great piece of work, but it might be somewhat outdated. First unzip the file, and then follow steps within the SDK readme.pdf.
Following the readme.pdf i do the following: To build the SDK, use the ./tools/build_sdk command from the root folder. I get multiple error but they are all related to the standard library such as:
iMX6_Platform_SDK/sdk/drivers/accelerometer/src/mma8451.c:31:10: fatal error: string.h: No such file or directory #include <string.h>
iMX6_Platform_SDK/sdk/include/sdk.h:40:10: fatal error: stdio.h: No such file or directory #include <stdio.h>
So how do I solve this? Do I cross compile the standard library or do I get the binary some other place?
SDK build by yocto is little bit different than normal arm toolchain.
I believe you used
arm-fslc-linux-gnueabi-gcc hello.c
but actually you need to use Makefiles or Macros like below,
${CC} hello.c -o hello
Write this directly into your terminal or put it into a makefile.

toquelib behaves different with static and dynamic linking

This is puzzling me...
I have a code that looks like this:
#include <stdio.h>
#include <pbs_ifl.h>
int doSomeStuff()
{
char *server_name;
int c;
server_name = pbs_default();
c = pbs_connect(server_name);
printf("pbs_errno %d\n",pbs_errno);
// do some stuff
pbs_disconnect(c);
}
When I compile it with:
gcc -static -o executablename sourcefile.c -ltorque
It works allright, compiling with '-static'. pbs_errno is 0 and I can do my stuff.
But if I remove the '-static' flag it starts giving me this message when I run it:
munge: Error: Unable to access "/var/run/munge/munge.socket.2": No such file or directory
So... I start the munge service (munged) and it stops complaining about it, but instead I get pbs_errno=15033 and can't get anything from the cluster (do my stuff).
Any ideas?
I don't know if I delete de question or answer it, but it seems so be solved... so I'm posting the solution here.
I had 2 versions of the lib installed, one via yum other via source.
Since only the compiled code had the static libs, when I was linking -static gcc was linking with the compiled code and when I was linking dynamic it was linking with the yum version.
I just had to enforce the linking with the right libs adding the following flag when liking:
-Wl,-rpath=/usr/local/lib

where are clang c++11 header files

I am trying to read and understand some of the c++11 code from clang-3.4. But I couldn't find standard headers. I am using mingw32 and build clang from source to default location at /usr/local/lib/clang/3.4.
I tried to look for and did
$ find |grep iostream
from that folder and it returned nothing. I can however compile code with fine.
Where are the clang implementation of c++11? Am I looking at the wrong folder?
--- Update ---
I built clang 3.4 from source under Windows XP 64-bit, using mingw32 (from mingw.org). I configured clang/llmv in MSYS using:
./configure --enable-pic --disable-docs --enable-targets=x86,cpp
So, I assume that clang is installed to /usr/local/, and indeed find clang/3.4 under usr/local/lib. But maybe the header files are elsewhere as suggested by the comment, I did another find/grep in the entire MinGW folder (containing MSYS) and still couldn't find the iostream file. The only thing I got was gcc version:
$ cd /c/mingw
$ find | grep iostream
./lib/gcc/mingw32/4.8.1/include/c++/iostream
./mingw32/lib/gcc/mingw32/4.8.1/include/c++/iostream
-- Update 2 ---
I tried install libcxx, using cmake
cmake -G"MSYS Makefiles" ../libcxx-3.4
make
, and got the following error:
...
[100%] Building CXX object lib/CMakeFiles/cxx.dir/__/src/support/win32/support.c
pp.obj
d:/temp/tdm/libcxx-3.4/src/support/win32/support.cpp: In function 'size_t wcsnrt
ombs(char*, const wchar_t**, size_t, size_t, mbstate_t*)':
d:/temp/tdm/libcxx-3.4/src/support/win32/support.cpp:134:88: error: 'wcrtomb_s'
was not declared in this scope
result = wcrtomb_s( &char_size, dst + dest_converted, dest_remainin
g, c, ps);
...
Clang builds separately from libc++, so you need to install it first to get that <iostream> include file.
Alternatively, you can instal MinGW, which comes with GNU libstdc++.

clang says "cstdlib file not found"

On an almost default install of Ubuntu 11.04 I installed clang.
I am trying to compile this:
#include <cstdlib>
int main(){
return 0;
}
g++ can deal with it just fine, but clang++ errors out: fatal error: 'cstdlib' file not found
Can someone explain why this happens? and what needs to be done to make this work?
I expected clang++ to be a drop-on replacement for g++.
Seems like your clang build is not searching the correct platform include paths. Try checking with
clang -v ...
where it is looking for headers (and check that your platform include paths are there). You might have to add additional include directories (e.g. /usr/include/c++/x.y).
You might want to take a look at the source file lib/Frontend/InitHeaderSearch.cpp, The method AddDefaultCPlusPlusIncludePaths does some distribution/gcc-version specific magic (I had to fix it for my own system once).

Resources