i am trying to iterate over a directory using Boost.Filesystem library.
The problem is that when i try to instantiate a path object, i get an std::length_error with the message "string too long" with strings of any length, even for example "pippo".
I have already tried all of these:
string s = "pippo";
path p(s);
path p(s.begin(), s.end());
path p(s.c_str());
path p("pippo");
I am on windows 7 with boost precompiled version 1.47 for vc++10.
Thank you in advance,
Luca
EDIT
this is the boost code executed (path.hpp line 129)
template <class Source>
path(Source const& source,
typename boost::enable_if<path_traits::is_pathable<
typename boost::decay<Source>::type> >::type* =0)
{
path_traits::dispatch(source, m_pathname, codecvt());
}
and the error is thrown from (path_traits.hpp line 174)
template <class U> inline
void dispatch(const std::string& c, U& to, const codecvt_type& cvt)
{
if (c.size())
convert(&*c.begin(), &*c.begin() + c.size(), to, cvt);
}
the function that throws is "convert". From the debugger i saw that both
&*c.begin()
and
&*c.begin() + c.size()
are correctly executed
You mentioned that Boost is pre-compiled for VC++10, but you didn't say which compiler YOU are using. If you are using Visual C++ Express you need to compile it yourself.
But, since I'm about to use boost::filesystem, I thought I'd investigate to learn a bit myself.
Firstly, you should almost never be putting an entire Boost namespace into your plain namespace wherever possible (especially if you are doing so with std!). Posting code like this makes it look like you are "using namespace" too much. If you don't want to type boost::filesystem everywhere, do this:
namespace fs = boost::filesystem;
fs::path p(whatever);
or
using boost::filesystem::path;
using std::string;
string foo("Hello!");
path p(foo);
Including Boost namespaces in your local namespace like you seem to can have disastrous consequences (or work fine, it's the luck of the draw). As you noticed, the function call that kills it is convert() - is there perhaps another convert() somewhere that is superseding it?
Next, you should enable automatic linking (for this library). The official Boost documentation says to use automatic linking. The Boost people are very smart (perhaps too smart - working with the time libraries is a pain...) It works well for Visual Studio 2010.
If that doesn't fix it, your precompiled Boost is using a different CRT (since the convert function appears to be in the Boost library). This can happen for many reasons, for instance, the VS2k10 service pack may be installed on your source/not on yours, etc.
The ultimate solution is to compile Boost yourself. It's very, very easy on Windows: download Boost sources, and extract to any directory. Then open a command prompt (start->run cmd.exe) and do:
cd\
cd "boost root directory"
boostrap
.\b2
Then just wait about 45 minutes on a Core 2 Duo 2.5GHz. It will generate the Boost libraries with the correct CRT. If you still have problems then, then there is something deeper wrong with your build system, such as linking against a static Boost library while using DLL CRT (you should link DLL Boost with DLL CRT).
A possible error can be found on the library you linked in the project
(release instead of a debug one).
For example.
Suppose you're using Visual Studio 2010 with "Debug" configuration active.
You have to link boost_filesystem-vc100-mt-gd-1_49.dll
boost_filesystem: basename of library
vc100: Visual Studio version (vc100 for VS2010)
mt: multithreading
gd: debug version
1_49: version
Maybe you've linked the library without the "gd".
Related
I have been making some applications that I would like to link to discord, specifically with Discord's SDK. The SDK comes with 64 and 32 bit x84 lib files, and a C++ folder full of the includes it needs, so I would assume C++ is supported.
However, I am very terrible at linking libraries or anything at that, and always run into issues when linking. I am using Dev C++ as my IDE, and my code is as follows:
#include <iostream>
#include "Discord/discord.h"
using namespace std;
void InitDiscord()
{
auto discid = 772671910668133376; //Not my actuall discord app ID, but real one does not make a difference
discord::Core* core{};
discord::Core::Create(discid, DiscordCreateFlags_Default, &core);
}
int main(){
InitDiscord();
cout << "Discord active";
while(1){
}
return 0;
}
and I am getting the error:
C:\TDM-GCC-64\x86_64-w64-mingw32\bin\ld.exe Discord Testing.o:Discord Testing.cpp:(.text+0x32): undefined reference to `discord::Core::Create(long long, unsigned long long, discord::Core**)'
for only the line discord::Core::Create(discid, DiscordCreateFlags_Default, &core); and not discord::Core* core{};
I am using C++17 and a newer TDM-GCC compiler, the same one that works for all of my other applications. I am including the .lib files and .dll files in the program's directory, and in the linker the only thing I am using is -discord_game_sdk.dll.lib which is a valid directory. I have also tried discord_game_sdk.dll.lib and putting the library in the same directory as the includes: Discord/discord_game_sdk.dll.lib. I have tried using both 32 bit and 64 bit libraries in all project and compiler directories with no change, and im sure this is something probably really simple, but nowhere have I found any example C++ discord programs or how to include their SDK.
If anyone could figure out what the problem is and how I can fix it, that would be very helpful and appreciated.
EDIT:
It appears that user4581301 was right, TDM-GCC and other Mingw compilers do not support .lib files, and will ignore them despite being linked. The SDK did not come with any other formats other than .dylib, .so, and .bundle.
This creates a somewhat new issue, I already have my compiler set up and cannot really switch to Visual Studio, so I need a way to convert .lib to .a somehow. A post here recommends http://code.google.com/p/lib2a/ , which requires a .def file, another file that did not come with the SDK, but apparently a program called gendef.exe that came with my compiler can create .def files from .dll files. That is indeed the case, however when attempting it I get the error:
C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\bin>gendef.exe discord_game_sdk.dll
* [discord_game_sdk.dll] Found PE image
* failed to create discord_game_sdk.def ...
with no other warnings. Now I need to know if I am converting wrong, if there is an easier workaround, or if one of the other file types can be converted or used. Any suggestions at this point are welcome and appreciated!
I built Qt from source (dlls) and am trying to build an application that uses the Qt dlls. I don't have a lot of experience with C++ so I'm running into what I'm sure is a very basic issue.
My builds are failing on the includes with errors like so:
Fatal error: QNetworkProxy: No such file or directory
Here is the g++ command I am using (I also used -L to add the correct folder to the lib path, but that also didn't work):
g++ -l..\..\wkqt\bin\QtCore4.dll -l..\..\wkqt\bin\QtNetwork4.dll -l..\..\wkqt\bin\QtWebKit4.dll -I..\include -Ishared -Ipdf -Ilib -Iimage -o ..\bin\wkhtmltopdf.exe pdf\*.cc lib\*.cc image\*.cc shared\*.cc
I tried in Visual Studio as well (assuming it wouldn't build, but I wanted to see if I could at least include the Qt dlls from there properly) and I am getting the same errors. Am I doing something wrong with the way I am compiling with g++? If I am linking with the Dlls properly then what is the proper way to use Qt functions from my code?
To clarify, I am not looking for how to properly use Qt. My question is: what is the proper way to use functions defined in any Dll from native C++ code? I apologize if this is a very basic question, but I'm unable to find a clear answer on Google and I don't have any experience with C++ and including third party libraries for use from C++ code.
DLLs can be used by dynamicly loading them and calling their used functions.
to call the exposed functions first define their syntax in the begining
suppose function is syntax is
BOOL MyFunction(int a,char* pszString)
then define syntax
#typedef BOOL (WINAPI *PMYFUNCTION)(int a,char* pszString)
then make object
PMYFUNCTION pfnMyFunction;
and get valid pointer by calling GetProcaddress after loadlibrarycall
HMODULE hlib= Loadlibrary("c:\\Mylib.dll");
if(hlib)
{ pfnMyFunction = (PMYFUNCTION)Getprocaddress(hlib,"MyFunction"); }
Hope this helps...
I have installed boost_1_54 on windows by checkout from svn and then
bootstrap
.\b2
QuantLib library dependent on boost compiles well all but one project: test-suite which uses BOOST_MESSAGE. this is undefined. I can see that there is no BOOST_MESSAGE in my version of boost.
Therefore is this QuantLib incompatibility or have I missed something?
On my linux boost version the same thing applies to BOOST_MESSAGE - it is undefined
I have seen this but I am not sure how to interpret this.
I'm afraid you gave us more credit than we deserved :)
We haven't compiled QuantLib against Boost svn yet. The latest I've tried is Boost 1.53 (the latest released version) in which BOOST_MESSAGE was still available.
Thanks for the heads-up, though. I'll patch the library so that it's ready for next version. As mentioned in the comments, it should be as simple as adding
#if BOOST_VERSION > 105300
#define BOOST_MESSAGE(msg) BOOST_TEST_MESSAGE(msg)
#endif
to test-suite/utilities.hpp.
on linux I had to add
libboost_unit_test_framework.so
to the Linker->Libraries and
#include <boost/test/unit_test.hpp>
#define BOOST_MESSAGE( M ) BOOST_TEST_MESSAGE( M )
is already present in test/test_tools.hpp.
on windows I have different #defines and this is not present, so I added it to the
unit_test_log.hpp
where BOOST_TEST_MESSAGE is defined (in boost files to avoid same issue again in the case of other applications using BOOST_MESSAGE).
BOOST_MESSAGE issue resolved but still can't disambiguate
const void* = boost::test_tools::check_is_close
and
const void* = boost::test_tools::check_is_small
because these are templates. so the solution is to remove it (test-suite compiles well) or use appropriate pointers to function templates
on Windows, after romoval or function
_use_check
in utilities.hpp
changed to not have pointers to TEMPLATE functions as default, so changed to:
void _use_check(
const void*,
const void*) const {}
there were still errors while building test-suite project. unresolved externals: fdmhestonfwdop, fdmblackscholesfwdop, fdmsquarerootfwdop. obviously this classes (headers+source) I had to add to Quantlib project, build library QuantLib-vc110-mt-gd.lib again and rebuild test-suite project then.
after pleasure with VS linker error "lnk1210 exceeded internal ilk size limit link with incremental no" (it really likes RAM, but on windows I have this resource quite limited), it is OK. compiled. : p
I installed EDG compiler in Windows i.e in "win32". After installation I am trying to run this simple code:
using namespace std;
int main()
{
cout<<"OM";
return 0;
}
I am getting errors like unidentified cout, etc
Actually I didn't give path dev libraries : there in read me file it is to give. Later I did gave path to libraries(VS C++ 2010)
Please provide me the MSDEV /include header files to download.
Please provide the location of the "\msdev\include" directory to download.
edit: in readme file they gave "No stream
I/O library is included; this is just very basic support."
if we gave iostream.h also .it shows ..many erros ..regarding that?
EDIT: Otherwise any one
Provide link to download EDG compiler (C++) for windows.Free ware
who already working successively with this....
As far as I see from their page, EDG do not provide a full compiler, but only a front-end; it does not include neither an optimizer/code generator neither a standard library. You simply cannot use just EDG to produce an executable.
You can find several free implementations of the C++ standard library (e.g. libstdc++ from GNU, to which I suppose you should add glibc for the C library subset), but without at least a code-generator backend all you can get from the front-end is the AST of the code gave in input.
Moreover, EDG C++ it's not free, neither it is sold to individuals; EDG license only the source code and only to corporations for a 40K$-250K$ price range. The links you're asking in your question would be illegal.
If you just need a compiler for Windows, there are several great alternatives, both free and not-free, some are listed e.g. in this question.
This is more of an answer than a question, because I've figured it out, at least as far as cleanly compiling the library. The main issue for me was to get shared_ptr working.
Ingredients:
Boost v. 1.45.0
The version of STLport at http://www.anddev.org/viewtopic.php?p=29939.
Version r4b of the NDK.
Directions:
In your Android.mk file add:
LOCAL_CFLAGS += -DBOOST_EXCEPTION_DISABLE -D_STLP_NO_EXCEPTIONS -DOS_ANDROID -D_STLP_USE_SIMPLE_NODE_ALLOC
Remove the call to __stl_throw_length_error at line 613 of stlport/stl/_string.h. You can use _STLP_NO_EXCEPTIONS if you like.
Edit boost/boost/smart_ptr/shared_ptr.hpp after line 261 to get rid of the call to boost::throw_exception in the shared_ptr constructor. I used #ifndef BOOST_EXCEPTION_DISABLE around the entire body of the method. (But see the answer below.)
Next you need to supply some missing pieces. Create a header file with the following:
#ifdef OS_ANDROID
#include <exception>
namespace std
{
struct bad_alloc : public exception { bad_alloc operator()(){}};
}
#endif
and a source file with a stripped-down exception class to support bad_alloc:
#ifdef OS_ANDROID
#include <exception>
namespace std
{
exception::exception() {}
exception::~exception() {}
const char* exception::what() const {}
}
#endif
Include the header wherever you're including boost/shared_ptr.hpp. Compile the source and add it to your library.
It turned out that this approach does not entirely work when compiling a debuggable library. The release library is compiled with -O2 which optimizes out some infelicities, but the debug library is done with -O0 which reveals some additional problems. Furthermore, I wasn't too happy about having to edit the boost files. So with some additional study, I've come up with the following solution.
First, don't edit any of the boost files. Instead add the following to the header within the std namespace:
struct bad_cast : public exception {bad_cast operator()(){}};
Next add the following to the source file:
namespace boost
{
void throw_exception(std::exception const&) {}
}
This now compiles and links into the application even with android:debuggable="true" in AndroidManifest.xml. It doesn't run in the emulator, but then it wasn't doing that before I included this library either.
Notably, NDK r5 comes with STLport, and the GNU STL, and so the hacks here are no longer going to be necessary now that there is a) STL support b) exception support in the NDK C++ compiler.
Another workaround for shared_ptr in particular is to use boost::intrusive_ptr instead. This is not always possible, but worked for my situation.
The current version of Android NDK (r9) now supports exceptions.
The capabilities of the various runtimes vary. See this table:
C++ C++ Standard
Exceptions RTTI Library
system no no no
gabi++ yes yes no
stlport yes yes yes
gnustl yes yes yes
stlport can get used in non-GPL binarys. It's still flagged as experimantal, but you can use it with clang and gcc.
See http://developer.android.com/tools/sdk/ndk/