Sorry in advance for a kind-of-dumb question - I'm pretty new to all this.
So I downloaded asio from here, and tried to #include asio.hpp, but got the following error;
fatal error: boost/config.hpp: No such file or directory
I thought this was rather odd, as it was suppose to be independent of Boost. I poked around a bit, and saw that I needed to define ASIO_STANDALONE, which I promptly did, only to be met with more errors where it tried to #include something else from Boost.
Is there just a big list of all the things I have to #define to tell it to be standalone or something? That would be very helpful.
This is an old question, however i had the same problem currenlty with Visual Studio 2013 and Asio 1.10.6. In Visual there is no switch nor compiler flag for c++11 features. Even with #define ASIO_STANDALONEAsio requires Boost.
Solution is to manually specify that our compiler is c++11 compliant. Just add:
#define ASIO_STANDALONE
#define ASIO_HAS_STD_ADDRESSOF
#define ASIO_HAS_STD_ARRAY
#define ASIO_HAS_CSTDINT
#define ASIO_HAS_STD_SHARED_PTR
#define ASIO_HAS_STD_TYPE_TRAITS
#include <path_to_asio/asio.hpp>
As noted on the Asio website:
When using a C++11 compiler, most of Asio may now be used without a dependency on Boost header files or libraries. To use Asio in this way, define ASIO_STANDALONE on your compiler command line or as part of the project options.
Thus even when ASIO_STANDALONE is defined, Asio will use Boost when:
Using a non-C++11 compiler.
When using certain features, such as stackful coroutines that are based on the Boost.Coroutine library.
With asio-1.10.2, the following program:
#include <asio.hpp>
int main()
{
asio::io_service io_service;
}
compiles with gcc 4.8.1, using -DASIO_STANDALONE -std=c++11 compiler flags. Without specifying the compiler to use c++11, compilation fails when attempting to include Boost header files.
Related
I am trying to compile OpenCV3 and put it into Qt project because Qt officially provides MinGW Version, so I didn't use MinGW-w64.
I enabled ENABLE_CXX11 and disabled ENABLE_PRECOMPILED_HEADERS in CMake.
Now the problem is MinGW does not contain std::thread.
I know the mingw-std-threads lib can fix it. but I don't want to modify OpenCV source code. Is there any other way to adding c++ thread feature to MinGW? or tell OpenCV using pthread by CMake?
BTW. I don't want use Qt's MinGW because I think using official MinGW to compile the lib shall be used in any version of Qt.
Update:
In OpenCV detection_based_tracker.cpp, there is a CV_CXX11 Marco choice to the using std thread or the pthread. But I didn't see anywhere define CV_CXX11.
Is part of detection_based_tracker.cpp code:
#ifdef CV_CXX11
#define USE_STD_THREADS
#endif
#ifdef USE_STD_THREADS
#include <thread>
#include <mutex>
#include <condition_variable>
#else //USE_STD_THREADS
#include <pthread.h>
#endif //USE_STD_THREADS
My environment:
windows 7 64bit
cmake-3.10.1-win64-x64
opencv-3.4.0
gcc 6.3
What I tried:
install CMake and MinGW
disable ENABLE_PRECOMPILED_HEADERS in CMake-gui
comment #define USE_STD_THREADS in detection_based_tracker.cpp line 48
configure and generate Makefile
Run mingw32-make
it's successfully compiled, but I have to modify OpenCV source code.
If you use the right version of MinGW, namely MinGW-w64, most toolchains builds have the modern threading features available.
You can e.g. use the installer or install it through MSYS2.
I'm writing some library code, which can optionally make use of a certain C++11 feature (thread_local objects). However, I've found a bug that occurs only with the POSIX threading model (the Win32 one works fine) in MinGW-w64's builds of g++.
So, how can I detect, using the preprocessor, whether the current compiler is a g++ with the POSIX threading model?
g++ -v yields ... Thread model: win32 or ... Thread model: posix depending on the difference, but I need a way to conditionally compile code (to work around the bug) that doesn't involve invoking an extra instance of g++.
Check whether the macro __WINPTHREADS_VERSION is defined. If so, you are using posix threads on MinGW.
For example:
#if defined(_WIN32) && !defined(__WINPTHREADS_VERSION)
Logic for MinGW win32 threads;
#else
Logic for MinGW posix threads or Linux/UNIX;
#endif
Examples/References:
http://savannah.gnu.org/support/?108150#comment0
https://projects.kde.org/projects/kdesupport/emerge/repository/revisions/master/entry/portage/win32libs/libssh/0002-add-a-way-to-test-ssh-connections-on-windows.patch#L114
I am new to C++ and plugin development. I am working with/for Unix and for the Firefox browser. So here we go:
I have a plugin which uses some classes from a own library. The problem is: it kills my browser asap. I cant even start my browser as soon as MyPlugin.so is in the plugin folder of the Firefox. The library is build and doesn't kill a desktop application that uses it.
My guess is that I failed at linking my library with CMake or forgot to include some stuff from FireBreath. So here are the two things I assume are wrong, maybe someone can help me out.
1) (wrong?) linking with Cmake:
I added some of these at the end of the CMakeLists.txt of my project. The paths are where the library is.
add_definitions(-L${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/bin)
add_definitions(-I${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/src)
add_definitions(-lcoala64) [name of the library]
add_definitions(-Wl,-rpath=${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/bin)
add_definitions(-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/harfbuzz -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lglib-2.0)
And used the prepmake.sh to generate my build files. Then I followed up with adding flags manually (because I dont know a better solution) to the in the /buid/projects/MyPlugin/CMakeFiles/MyPlugin.dir/link.txt
-L/home/username/swp/dev/lib/bin
-I/home/username/swp/dev/lib/src
-lcoala64 -Wl,-rpath=/home/username/swp/dev/lib/bin
Afterwards I could build the plugin. It builds, so one could assume I have linked correctly. But said crashes appear as soon as I want to use it.
2) Do I use the library wrong?
I include like this in MyPluginAPI.h:
#include <string>
#include <sstream>
#include <boost/weak_ptr.hpp>
#include <boost/smart_ptr.hpp>
#include "JSAPIAuto.h"
#include "BrowserHost.h"
#include "X11/X11KryptoKoala.h"
//Include from my own library:
#include "../../../lib/src/Key.hpp"
As soon as I add the following line to MyPlugin.cpp I get the mentioned crashes while the same line works without a problem in the desktop application that uses the same library:
Key key(password_);
Now I hope this isn't a too big wall of text and someone is willing to investigate and answer to me.
You shouldn't use add_definitions() in that way. CMake allows to differentiate your directives in different categories, so that they only go in the necessary command line. You should use:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
include_directories(/usr/include/gtk-2.0
/usr/include/cairo
etc. etc.
)
add_library(the_name_of_your_target gtk-x11-2.0 gdk-x11-2.0 ETC. ETC.)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../lib/bin)
Furthermore, there are FindPackage functionalities that can help you setting automatically variables containing the name of your libraries, their directories, their include path.
Most information can be found here and here
Then: What is then prepmake.sh? Are you running cmake at all? Can you use cmake-gui, and then select one canonical build system, like make or ninja?
Finally: It could be that you have a crash because your library are not in your library path. I assume you are under linux, here are some ideas: LD_LIBRARY_PATH vs LIBRARY_PATH and LD_LIBRARY_PATH
I am using Microsoft Visual C++ 2010, and I need to make an application that does not require the libcurl dll. I am defining CURL_STATICLIB in the preprocessor directives and linking to libcurl.lib, libcurl_static.lib, ws2_32.lib, and winmm.lib, but it still requires the dll to work. If I only link to libcurl_static.lib, it has undefined external symbol errors. How can I get it working?
I have also tried building the source but I get 13 errors (wow, unlucky number) that all say "error C2011: 'pollfd' : 'struct' type redefinition". Could someone help me get libcurl working?
There is no simple answer :)
Libcurl depends on other third party libs (it depends on binary distribution that you are using). As you get rid of DLL - you'll have to link with corresponding third parties manually.
Ok, so the first point is that you should not link to libcurl.lib as it binds you to DLL which you don't want to.
Second point - when you are linking with libcurl_static.lib then (as mentioned above) you'll have also to link with libraries it depends on. Simple way to do that is to do something like this:
#if defined CURL_STATICLIB
#if defined _DEBUG
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\lib\\Debug\\curllib_static.lib")
#else
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\lib\\Release\\curllib_static.lib")
#endif
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\libeay32.lib")
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\openldap.lib")
#pragma comment(lib, "libcurl-7.19.3-win32-ssl-msvc\\ssleay32.lib")
#endif
But this way - you'll get three more dependencies. Alternatively, you can search for a way to link with them statically, but it is a different story.
As another alternative - you could rebuild libcurl_static.lib from sources after disabling all the features you don't need thus removing unwanted dependencies (as described in "Disabling Specific Protocols in Win32 builds" of INSTALL file).
And final point - as libcurl has quite poor support for windows compilation from sources, I'd recommend you to revisit the idea of getting rid of curllib.dll.
I got a static build of libcurl to compile and link by specifying both HTTP_ONLY and CURL_STATICLIB in the preprocessor directives of the libcurl project and my application. This eliminates all the dependencies required by protocols you likely do not need. The application now works without requiring any DLLs at all.
Beside the above, I just needed to make sure libcurl.lib and the path to the curl include files were set in the application's visual studio project settings.
References I used:
Disabling Specific Protocols in Win32 builds:
http://curl.haxx.se/mail/lib-2011-12/0123.html
Using libcurl in Visual Studio (out-dated):
http://curl.haxx.se/libcurl/c/visual_studio.pdf
I am trying to include 2 platform-specific stdafx.h files in my .cpp file, but the compiler is unhappy when I try to #ifdef it.
#ifdef _WIN32
#include "stdafx.h"
#elif _MAC
#include "MAC/stdafx.h"
#endif
You may wonder why I am using stdafx.h in the Mac code, but that is not important at the moment :).
When I try to compile the code on Windows, I receive: Fatal Error C1018. I tried enclosing other header files with #ifdef in the same file, and the compiler was happy. Therefore, it looks like Windows doesn't like stdafx.h to be #ifdef-ed, or that Windows only allows #include stdafx.h
to be the first line in the file.
So my question is, why?
Kat
When the compiler includes a pre-compiled header, it basically "forgets" anything that came before the header. Thus your #elif isn't matched to a #if anymore.
This is because you have Precompiled Headers turned on - turn it off and you should be fine.