I am using boost.build to compile a c++ code which references a library, CGNS, but am having some difficulty with using boost.build to do so. CGNS compiles to a library, with a folder for the platform, for example [path]/LINUX for the linux build. I would like to include the library [path]/LINUX/libcgns.a in the build. I would like this to be cross-platform, so that the LINUX directory is referenced for LINUX builds and the WIN directory is used for WIN builds (I believe there are platform conditionals for this).
I managed to include the library header files, but how do I go about the conditional include of the library? My simple test Jamroot.jam, where main.cpp is just an example from the CGNS docs.
exe CGNSTest
: src/main.cpp
: <include>../Dependencies/cgnslib ;
Also, I would like to build in the CGNS library into my binary (static reference?)
Using two references, http://www.highscore.de/cpp/boostbuild/, and http://www.boost.org/doc/tools/build/doc/userman.pdf, I created something that works, but it may not be the ideal.
lib cgns
: # sources
: # requirements
<name>cgns
<target-os>linux:<search>../Dependencies/cgnslib/LINUX
<target-os>windows:<search>../Dependencies/cgnslib/WIN32
: # default-build
: # usage-requirements
<include>./../Dependencies/cgnslib ;
alias static_libraries : cgns : <link>static ;
exe CGNSTest
: src/main.cpp static_libraries
: <target-os>windows:<linkflags>/NODEFAULTLIB:MSVCRTD ;
Related
I'm coding an application using gtkmm with Eclipse CDT and I created a Meson project, everything compile but I'm unable to make the indexer look for the gtkmm headers or any other headers that aren't part of the standard library.
Here is my meson.build file
project('gread', 'cpp')
subdir('src')
include_dir = include_directories('/usr/include/gtkmm-4.0/gtkmm')
gtkdep = dependency('gtkmm-4.0')
executable('gread', 'main.cpp', dependencies : gtkdep, include_directories : include_dir)
By any chance do someone know how to correct that ?
[UPDATE]
Problem partially solved,
I've added gtkmm-4.0 to the includes path like this :
it seems logic, because the include folder is the root for all include files, so 1 mystery solved.
But some class members are still unresolved. Any idea why ?
I'm porting a shared library from CMake to QMake (for better integration with the rest of our codebase), and am having trouble in Windows with having qmake generate both the .lib and .dll files.
I have ported this over to Linux and MacOS (easier with Unix shared library formats), but am having trouble with Windows.
Please note that I am not using the Mingw compiler, but the MSVC 2015 compiler. Unfortunately, I can't use the Mingw compiler for various reasons.
Relevant code in my .pro file:
Qt -= core gui #not using the qt library
CONFIG += c++14 warn_on
TEMPLATE = lib
TARGET = MyLibrary
With CMake, I was able to set certain .h files as PUBLIC_HEADER files, and after running make install, it generated the proper .lib and .dll files.
But with qmake, it only generated a very tiny .dll file (<15kb). I tried adding CONFIG += static but that created a .lib file with all the symbols there, not the shared library files I am looking for.
Edit: After looking more into it, a better question could be:
Is there a qmake equivalent (or workaround) of CMake's PUBLIC_HEADER property?
In a nutshell: #Matt is right, you need to take active action in your source code to export classes, functions and other symbols. This is mandatory in Windows, but it is also a recommended practice in Unix. When the MSVC++ compiler sees exported symbols, it automatically creates both the .DLL and the .LIB import library.
To do this in a cross-platform way with qmake, a nice guide is following the pattern of the Qt Creator wizard: Welcome -> New Project -> Library -> C++ library. Project location..., name: 'testlib' (for instance). Next, next, choose your kit, next and finish. The files created by the wizard in the project directory are:
testlib.cpp
testlib_global.h
testlib.h
testlib.pro
testlib.pro.user
The interesting bits are in testlib.pro:
TEMPLATE = lib
DEFINES += TESTLIB_LIBRARY
And the header "testlib_global.h"
#ifndef TESTLIB_GLOBAL_H
#define TESTLIB_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(TESTLIB_LIBRARY)
# define TESTLIB_EXPORT Q_DECL_EXPORT
#else
# define TESTLIB_EXPORT Q_DECL_IMPORT
#endif
#endif // TESTLIB_GLOBAL_H
This header should be included in other headers, that would be using the TESTLIB_EXPORT macro like this (testlib.h):
#ifndef TESTLIB_H
#define TESTLIB_H
#include "testlib_global.h"
class TESTLIB_EXPORT Testlib
{
public:
Testlib();
// ...
};
The key is to define TESTLIB_LIBRARY in the project .pro that builds the library, so the TESTLIB_EXPORT macro is defined as Q_DECL_EXPORT, which in Windows is defined as __declspec(dllexport), and avoid defining TESTLIB_LIBRARY in the projects using the library. More about this here.
Now, the second part of your question. In CMake documentation, it says:
PUBLIC_HEADER
Specify public header files in a FRAMEWORK shared library target.
Shared library targets marked with the FRAMEWORK property generate
frameworks on macOS, iOS and normal shared libraries on other
platforms. This property may be set to a list of header files to be
placed in the Headers directory inside the framework folder. On
non-Apple platforms these headers may be installed using the
PUBLIC_HEADER option to the install(TARGETS) command.
So the PUBLIC_HEADER attribute is only about installing the public headers. To do so in qmake, you need to use INSTALLS in testlib.pro, for instance:
unix {
target.path = /usr/local/lib
headers.path = /usr/local/include
}
!isEmpty(target.path) {
INSTALLS += target
}
headers.files = $$HEADERS
!isEmpty(headers.path) {
INSTALLS += headers
}
I want to use C++ OpenCascade (OCE) libraries within a C++ program with vs2017 inside a linux subsytem (ubuntu) from windows 10.
I compiled OCE into the linux subsystem; I also have the OCE compiled binaries in windows.
When I try to include a header from OCE in my code (#include <Adaptor2d_Curve2d.hxx>), I get this error :
error : Adaptor2d_Curve2d.hxx: No such file or directory
error : #include <Adaptor2d_Curve2d.hxx>
error : ^~~~~~~~~~~~~~~~~~~~~~~
error : compilation terminated.
I added OCE include path in my vs project in additional include directories from using $(ProjectDir) or $(RemoteRootDir) path. I checked, the paths are corrects.
I have created a linux console application.
My code :
// from oce
#include <Adaptor2d_Curve2d.hxx>
int main()
{
printf("hello from CAO3DConverterTestApp!\n");
return 0;
}
I've added theses lines into Additional Include Directories in my project settings
$(ProjectDir)..\oce-0.18.3\include\oce
$(RemoteRootDir)..\oce\build\inc
So what is the procedure to add external libs and headers in C++ code using vs2017 in linux subsystem from windows 10 ?
Here is a minimal projet with Boost dependancies instead of OCE
build a c++ linux console app with vs2017, using ubuntu linux subsytem.
include boost headers path in Additional Include Directories from project properties
add #include <any.hpp> (header from boost) into main.cpp file
The -I statements are corrects -I "C:\<myPath>\dependencies\boost_1_68_0\boost\", but I still have the error
error : any.hpp: No such file or directory
error : #include <any.hpp>
error : ^~~~~~~~~
error : compilation terminated.
What else should I do ?
refs : https://blogs.msdn.microsoft.com/vcblog/2017/02/08/targeting-windows-subsystem-for-linux-from-visual-studio/
Can't really debug your project without a minimal example, but here is something that can help you figure out what is going on:
In VS2017 right click your project, select properties. Under C/C++ choose command line.
Here you can see the command line the IDE is using to compile your source files. Check all /I statements and make sure one of them points to where Adaptor2d_Curve2d.hxx is located.
I want to use this library c++ library in my code on external directory, which I have build with cmake (I'm new with it), as the compiling tutorial explain. After this, what files (or makefiles) do I'm suppose to add to my directory to do things like this is my code
#include "rpc/server.h"
I saw something about importing static libraries that would have to add a CMakeLists.txt to my directory and compile my main code with something as
g++ -static main.cc -L<librpc.a directory> -lrpc -o main
But getting this:
fatal error: rpc/server.h: No such file or directory compilation terminated.
I have searched the web about these procedures but I'm not having sucess on this. Could someone help
First you need to add the rpc library to the project as an imported library, and subsequently you must specify target properties such as the imported location and the include directories.
add_library(rpc SHARED IMPORTED)
set_target_properties(rcp
PROPERTIES
IMPORTED_LOCATION "${rpc_LIBRARIES}"
INCLUDE_DIRECTORIES "${rpc_INCLUDES}"
)
After you've successfully added the rpc library to the project, just add rpc as a target to your executable.
add_executable(your_test_program main.cpp)
target_link_libraries(your_test_program PRIVATE rpc )
I have a project with some requirements, one of which is to set the c++11 compiler/linker flags:
jamroot.jam:
project
: requirements
<toolset>clang:<cxxflags>"-stdlib=libc++ -std=c++11"
<toolset>clang:<linkflags>"-lc++"
# ... etc
;
lib mylibrary
: #sources
[ glob source/*.cpp ]
/boost/filesystem
/boost/system
/boost/thread//boost_thread
;
The library-specific sources are being compiled with the necessary c++11 flags, however the Boost libraries mentioned do not. This is causing no end of binary incompatibilities and linker errors.
I do not want to specify the cxxflags explicitly in either the user-config or the command line. I would like to make sure the jamroot/jamfiles are all that is necessary to build the project properly.
How do I "pass in" the desired cxxflags to the dependent Boost libraries?
Update: I recently tried using an alias to accomplish my goal. From the docs:
Another use of the alias rule is to change build properties. For example, if you want to use link statically to the Boost Threads library, you can write the following:
alias threads : /boost/thread//boost_thread : <link>static ;
However setting this up for boost_filesystem and rebuilding, say, path.cpp still omits the properties I am trying to build with.
This was resolved by setting up a feature (thanks to Steven Watanabe):
feature.feature cpp11 :
on :
composite optional propagated
;
feature.compose <cpp11>on :
<cxxflags>"-stdlib=libc++ -std=c++11"
<define>BOOST_NO_CXX11_NUMERIC_LIMITS=1
<linkflags>"-lc++"
;
project
: requirements
<cpp11>on
# ... etc
;
Apparently this is the only way to get variables to propagate to dependent libraries.