MinGW-w64 string array crashing - c++

If I try to compile and run this
#include <string>
int main()
{
std::string strs[5];
return 0;
}
I get an error message of
The procedure entry point ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1Ev could not be located in the dynamic link library (path to exe).
I am using mingw-w64 gcc version 6.2.0 (i686-posix-dwarf-rev1) and have already tried (i686-posix-sjlj-rev1).
Is there another compiler version that does not encounter this bug or something I can do to my code to make it compile?

Related

Trying to use Boost library on Codeblocks gives an undefined reference

I'm trying to use the boost library on CodeBlocks, but I'm new to it and I can't seem to be able to link it properly.
The boost folder(version 1.70) is in the same folder of my main.cpp, and the library I'm trying to access is libboost_filesystem-mgw92-mt-x64-1_70.a;
Here is my code:
#include <iostream>
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path l_path("C:\\Hello.txt");
if(boost::filesystem::exists(l_path))
{
std::cout<<"exists!"<<std::endl;
}
else
{
std::cout<<"no";
}
return 0;
}
And some screenshots of my settings and of the error
Thank you!
Undefined reference to _Unwind_Resume suggests that you build Boost with different compiler than your project or you choose different type of exception handling.
Check if you're using the same compiler in both cases.
It might be also caused by building your project using gcc instead of g++. You should check that as well. In this case switch to g++ or explicitly link against libstdc++, by adding -lstdc++ to compiler flags.

How to link Qt codes to C++ codes (or C) in Mac using Macports?

I have installed Qt using Macports. However, I do not know how to link Qt into the code ... what is the exact command to compile the code, the include path, library path and the name of the library. Could any one help me with this? I use clang and g++ as the main C++ compiler.
#include <Qdebug>
#include <iostream>
int main()
{
cout << "Test compilation.";
return 0;
}

compiling C++ code with intel compiler on Mac error: expected an identifier

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.

Undefined reference to std::*something* when linking library staticly

I've compiled some of my code into a static library. Everything from this library begins with Glow or GLOWE prefix. At the moment, I'm testing the library in Linux (Ubuntu 14.04). I made a simple program to check if I did everything correctly.
#include <GlowSystem/Package.h>
int main(void)
{
GLOWE::Package package;
return 0;
}
GLOWE::Package is a class. It uses libzip and zlib (and standard c++ files eg. string). I link both libzip and zlib. When I try to compile, it fails with some linking errors.
Build log (at pastebin)
I thought that these errors are caused by too old libstdc++, but this code compiles:
#include <string>
using namespace std;
int main(void)
{
string a;
a.resize(5000);
return 0;
}
I'm at my wits' end and I have no idea what to do. I will appreciate any help.
It looks like your linker options are incorrect:
../GlowE/GlowEngine/bin/Debug/libGlowEngine.a /usr/lib/x86_64-linux-gnu/libzip.a /usr/lib/x86_64-linux-gnu/libz.a
Try:
-l../GlowE/GlowEngine/bin/Debug/GlowEngine -l/usr/lib/x86_64-linux-gnu/zip -l/usr/lib/x86_64-linux-gnu/z

linking jsoncpp on Ubuntu

I try to use jsoncpp library with c++ on Ubuntu.
I compiled the code and built the library with scons.
Now I can compile a simple programme:
#include "json/json.h"
#include <json/value.h>
#include <json/writer.h>
int main()
{
return 0;
}
I use this command to compile:
g++ test.cpp -usr/lib/libjson_linux-gcc-4.8_libmt
I conclude that the compiler knows where to find the library.
The problem comes when I declare a json object:
Json::Value root;
Then I have this error message:
undefined reference to « Json::Value::Value(Json::ValueType) »
How can I fix this problem?
For CodeBlocks (Ubuntu 14.04)
I have faced same problem in my codeblocks IDE after installing jsconcpp. This is how I rectified my problem.
Got to project>Build Options>linker settings and in the link libraries add jsconcpp and click ok