undefined reference to `wcstof' - c++

I have a simple program that compiles fine but fails to link due to my passing a wide string to std::stof. If I pass a standard non-wide string to stof, the program compiles and links with no issues.
#include <iostream>
#include <string>
int main(int argc, char** argv)
{
using namespace std;
float f = stof(wstring(L"53.42"));
cout << f;
return 0;
}
c:/mingw/lib/gcc/mingw32/9.2.0/include/c++/bits/basic_string.h:6636: undefined reference to `wcstof'
I'm compiling with mingw 9.2.0 and have tried linking mingwex manually, but doing so doesn't make a difference. g++ main.cpp -lmingwex
What is the problem?

Related

linux + visual studio 2013 + visualgdb, undefined reference to 'dlopen'

#include <iostream>
#include <dlfcn.h>
using namespace std;
bool LoadEESQuote()
{
void* m_handle;
m_handle = dlopen("libEESQuoteApi.so", RTLD_LAZY);
return true;
}
int main(int argc, char *argv[])
{
LoadEESQuote();
return 0;
}
it is said
need -ldl to compile
, so I set:
project properties-Configuration Properties-NMake-Additional Options: -lrt -ldl
but I still get error.
Please help me
Thanks to n.m.
VisualGDB Project Properties- Makefile settings -Additional linker inputs: -ldl
and it is worked out

undefined reference to `boost::filesystem::path::codecvt() CodeBlocks Windows

I'm trying to use boost on CodeBlocks. I have codeblocks configured with MinGW-w64. I alredy have included the following libraries in the linker settings
libboost_system-mgw73-mt-d-x32-1_66.a
libboost_system-mgw73-mt-x64-1_66.a
libboost_filesystem-mgw73-mt-x64-1_66.dll.a
I also try changing the order...
This is the source code
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
namespace fs = boost::filesystem;
int main(int argc, char* argv[])
{
if( fs::is_directory("."))
cout << "Works!" << endl;
return 0;
}
i have read many "solutions" but they didn't work.
i tried:
changing the #include for this
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
#undef BOOST_NO_CXX11_SCOPED_ENUMS
creating a new compiler flag with boths values
-lboost_filesystem-mt
and also
-lboost_filesystem
but i always get the same error
...\boost_1_66_0\boost\filesystem\path.hpp|981|undefined reference to `boost::filesystem::path::codecvt()'|

C++ compilation error: ‘pair’ does not name a type

I'm trying to compile very simple c++ program by g++ compiler.
//main.cpp
#include <stdio.h>
using namespace std;
typedef pair<int,int> pii;
int main(int argc, char *argv[])
{
printf("Hi");
return 0;
}
But I'm getting compilation error: ‘pair’ does not name a type
Compile line: g++ main.cpp -o main.out
OS: Ubuntu 16.04 lts
g++: gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)
If I just add #include<iostrem> program compiles and runs successfully:)
#include <stdio.h>
#include<iostream>
using namespace std;
typedef pair<int,int> pii;
int main(int argc, char *argv[])
{
printf("Hi");
return 0;
}
Do you know, why is this happens?
My fault, answer is easy:)
1) For using pair I should include <utility>.
2) <iostream> somewhere includes <utility>, that's why after adding it program compiles successfully:)

Simple netbeans C++ project doesn't compile

I installed Netbeans and as C++ compiler I installed cygwin. I made a simple project to test out my installation, this is the code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "test";
return 0;
}
This is the error message that it gives: http://pastebin.com/jRRh7MPi
I hope you guys can help me out.
You need to either explicitly link to C++ standard library, or compile using g++ instead of gcc.

Dynamic library using static library in c++ name mangling error

I am trying to create a dynamic(.so) wrapper library along mongoDB c++ driver. There is no problem with the compilation but when I test it in a C++ sample program i get the error
undefined symbol: _ZN5mongo18DBClientConnection15_numConne
which i assume has something to do with name mangling issues.
I compiled the library as
g++ -fPIC -shared mongoquery.cpp -I/pathto/mongodriver -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -o libmongoquery.so
Here's the program I am using for testing:
#include <iostream>
#include <dlfcn.h>
#include "mongoquery.hpp"
using namespace std;
int main()
{
void *lib_handle;
int (*fn)(int *,string);
lib_handle=dlopen("./libmongoquery.so",RTLD_NOW);
if(!lib_handle)
{
cerr<<"Error"<<dlerror();
return 1;
}
fn=(int (*)(int *,string))dlsym(lib_handle,"count_query");
string q="{}";
int n;
(*fn)(&n,q);
cout<<n;
dlclose(lib_handle);
return 0;
}
the header mongoquery.hpp contains
#include <iostream>
#include <client/dbclient.h>
#define HOST "localhost"
#define COLLECTION "test.rules"
using namespace mongo;
using namespace std;
class mongoquery
{
private:
string q;
mongo::DBClientConnection c;
public:
mongoquery(string);
int result_count();
};
int count_query(int *,string);
Thanks
The answer can be followed from this question
Dynamic library uses statics libraries, undefined symbols appears
Added for achival purpose