I need to use PostgreSQL C++ library. I simply include pqxx/pqxx in my helloworld code but I don't use it! When I've run it I've got an error:
"db:free(): double free detected in tcache 2"
#include <iostream>
#include <pqxx/pqxx> //<------- causes db:free(): double free detected in tcache 2
using namespace std;
int main(int argc, char ** argv)
{
std::cout << "Hello world" ;
return 0;
}
I installed libpqxx from master branch of its github repository, with configure, make, make install.
I have a debian unstable and I also have an installed libpq-dev and a libpq5 package. Documentation said:
"Do I need libpq when I use libpqxx? Yes; libpqxx is built on top of libpq."
I've compiled it with g++ main.cpp -lpqxx -lpq
How can I eliminate this problem?
thx,
Zamek
Related
I just updated Gurobi to version 7.5.1 on Linux (Ubuntu)--this is the newest version available.
Problem Any time I try to compile any code that uses Gurobi--for example, the examples included in /opt/gurobi751/linux64/examples, I just get a string of undefined reference errors (e.g. undefined reference to GRBModel::set(...)). I would consider the problem to be solved if I can go to the directory /opt/gurobi751/linux64/examples/build and run the command make run_diet_c++ and have it compile and run.
Attempted Fixes
(1) I have set $GUROBI_HOME in my .bashrc file--it points to the correct directory. $LD_LIBRARY_PATH and $PATH have been updated as well. They all point to the correct directories.
(2) I have a valid Gurobi license. If I write a .lp file and run it like gurobi_cl model.lp, it runs correctly. Running gurobi_cl --version gives the expected output (i.e. version 7.5.1).
(3) If I try to compile the C version (with make run_diet_c) everything works as expected.
More Information
I created the following test file in my home directory:
#include <stdio.h>
#include "gurobi_c++.h"
int main(int argc, char **argv)
{
GRBVar x;
std::cout << "Hello, world!" << std::endl;
return 0;
}
I then compile using g++ with the following command:
g++ -Wall test.cpp -o executable -I/opt/gurobi751/linux64/include -L/opt/gurobi751/linux64/lib -lgurobi_c++ -lgurobi75
This compiles and runs without complaining. However, I tried this example:
#include <stdio.h>
#include "gurobi_c++.h"
int main(int argc, char **argv)
{
GRBEnv* env = 0;
try {
env = new GRBEnv();
GRBModel model = GRBModel(*env);
model.addVar(0, 1.0, 1.0, GRB_CONTINUOUS, "TheVar");
model.update();
model.optimize();
} catch (...) {
std::cout << "Exception during optimization" << std::endl;
}
delete env;
return 0;
}
and compiled it with the same command, and it failed. So it seems like the include statement is working fine, but somehow it's not linking to the library correctly?
Please let me know if more information is needed. Also, if it's not clear, I don't know very much about the compilation and linking process, which is probably hindering me here.
You need to compile the libgurobi_c++ for your g++ version.
First, go to the folder
cd /opt/gurobi751/linux64/src/build/
make
Now, you need copy the compiled file to lib folder:
cp libgurobi_c++.a ../../lib/
You will compile and run.
My laptop can not compile a simple c++ code since yesterday, it works perfectly fine before.
The c++ code is can be a hello-world code in main.cpp file.
#include <iostream>
using namespace std;
int main(int argc, char** argv)
{
cout<<"Hello World"<<endl;
return 0;
}
I am trying to compile the code by
icpc main.cpp
The error information is
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/algorithm(637),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/__string(56),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/string_view(171),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/string(470),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/__locale(15),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios(216),
from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream(38),
from main.cpp(1):
/Library/Developer/CommandLineTools/usr/include/c++/v1/type_traits(2065): error: expected an identifier
: public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {};
compilation aborted for main.cpp (code 2)
A few information:
I am using icpc (ICC) 17.0.4 20170411, it is installed from Intel® Parallel Studio XE Composer Edition for C++ macOS.
My mac is MacBook Pro (15-inch, 2017), version 10.12.6.
If I use gnu compiler, it works fine. While my code needs to use intel's compiler.
The code works before, do not know while it becomes this. I have already tried restarting the systems.
======================================================================
Update1: The problem happened after I update my "Command Line Tools for Xcode". It looks like the /Library/Developer/CommandLineTools/usr/include/c++/ is not right.
======================================================================
Update2: This is can be solved by using icpc -std=c++11 main.cpp
However when I change my main.cpp to
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
tuple<vector<int>, vector<int>, vector<int>>
getAllBlockMeanErrorTuple(const vector<int> &vec)
{
vector<int> fact, mean, err;
fact.resize( vec.size() );
mean.resize( vec.size() );
err.resize( vec.size() );
return make_tuple(fact, mean, err);
}
int main(int argc, char** argv)
{
cout<<"Hello World"<<endl;
return 0;
}
It has error again even if I use icpc -std=c++11 main.cpp
/Library/Developer/CommandLineTools/usr/include/c++/v1/__tuple(401): error: type name is not allowed
-> __all<typename enable_if<_Trait<_LArgs, _RArgs>::value, bool>::type{true}...>;
detected during:
I encountered the same issue while upgrading command line tools to the version of September 2017
While not finding a proper solution, I reinstalled previous version ( April 2017) of command line tools and it solved the problem (https://developer.apple.com/download/more/#).
I am looking forward to having a clean solution.
EDIT (5/12/17):
I solved the issue by recompiling everything using gcc. At compilation, Intel compilers will use the compiler that responds to gcc and g++ in the path. An installation with homebrew and some symlink in /usr/local/bin pushes the newly installed gcc in front of clang and then avoids gcc to change at each system update. Hope it helps.
Try to check that you are using right settings
and GNU is working because it automatically set to C++
try to set compiler to c++
hope this works.
OR You can use xcode to write c++ Code.
This is a problem I've been having for a solid week now; I am fairly new to C++ programming and am trying to compile the very basics of the socket.io C++ library in xcode 6.
This is the code I am using.
#include <iostream>
#include <string>
#include "sio_client.h"
int main(int argc, const char * argv[]) {
sio::client h;
h.connect("http://127.0.0.1:3000");
}
The build settings under target are:
Library search path: /usr/local/Cellar/boost/1.58.0/lib
User Header search path: /usr/local/Cellar/boost/1.58.0/include, "$(SRCROOT)/boost/socket.io-client-cpp/lib/websocketpp"and "$(SRCROOT)/boost/socket.io-client-cpp/lib/rapidjson/include"
I have installed Boost using brew install boost --c++11 and imported the libc++.dylib and tried the libc++.6.0.9.dylib as frameworks into the project.
And I am getting the following compiling error.
Note: following tutorial from - https://github.com/socketio/socket.io-client-cpp.
Can anybody PLEASE! Help me, I am dying here :P
I'm trying to compile a C++ project that requires Boost. I downloaded the latest build from the web site and copied the appropriate files to the appropriate libs folder (I'm using MinGW). When I compile, I'm get this error:
In file included from main.cpp:4:0:
headers.h:59:29: fatal error: boost/foreach.hpp: No such file or directory
compilation terminated.
I can find a working copy of foreach.hpp but I shouldn't have to move code files manually.
Solution
I had copied boost to the wrong folder.
I got this error on Ubuntu 12.10 when trying to use boost with a C++ application without the libraries installed:
el#apollo:~/foo8/33_parse_file$ g++ -o s s.cpp
s.cpp:3:29: fatal error: boost/foreach.hpp: No such file or directory
compilation terminated.
From this code:
#include <iostream>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
int main(){
cout << "hi";
}
I'm on Ubuntu 12.10 so I installed Boost like this:
sudo apt-get install libboost-all-dev
Then on recompile, it works and now I can use boost!
#include <iostream>
#include <string>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;
int main(int argc, char** argv)
{
string text = "token test\tstring";
char_separator<char> sep(" \t");
tokenizer<char_separator<char> > tokens(text, sep);
BOOST_FOREACH(string t, tokens)
{
cout << t << "." << endl;
}
}
Prints the three words token, test, string
You should make sure that your include path is set correctly. Assuming you downloaded Boost 1.47.0 your path should contain the location to your Boost installation up to the boost_1_47_0 directory, but leaving out the boost one, e.g.
/path/to/boost/boost_1_47_0
and not
/path/to/boost/boost_1_47_0/boost
On Fedora and Centos yum install -y boost and yum install -y boost-devel
I'm trying to compile the simplest program on MacOS 10.6 like:
$ g++ -o hello hello.cpp
the following source:
#include <iostream>
int main (int argc, char * const argv[]) {
std::cout << "Hello, World!\n";
return 0;
}
I'm getting the error:
hello.cpp:1:20: error: iostream: No such file or directory
hello.cpp: In function ‘int main(int, char* const*)’:
hello.cpp:4: error: ‘cout’ is not a member of ‘std’
So obviously I have to add the include path somewhere. My question is where can I find the include directories and how can add them globally (I don't want to provide the include path whenever I want to compile).
I just installed the XCode 3.1.4 and managed to compile it via Xcode, but not via command line. I found some header files in this directory:
/Xcode3.1.4/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers
and tried to add it to the HEADER_SEARCH_PATHS after reading this question, but no luck.
I'm developing on Linux and everything is working fine there, but I want to continue doing that on MacOS. Any help?
On my Mac, that include file is in /usr/include/c++/4.0.0/iostream . Are you sure
you have all the command-line development tools installed? They might not be by default;
I'm pretty sure I had to install it manually when I first set up my Mac. There should be a "developer tools" package somewhere on your OS X installation media.
Or, if you want to make sure you're getting the latest version, you can download it from:
http://developer.apple.com/technology/xcode.html
$ g++ -o example.bin example.cpp //to compile
$ ./example.bin //to run
It's code:
#include <iostream>
using namespace std;
int main () {
cout << "Hello, World!\n";
return 0;
}