How to build and run C++ API demos in gmsh? - compilation

I want to use gmsh C++ API to develop software.
I can build the project using cmake from source file on Ubuntu and get a executable file "gmsh".
My problem is:
How to compile the program as a shared library?
How to compile C++ API demos with the shared library and run it?
May be it is a stupid problems, but I have trapped here for hours.
Is there any step by step instructions can help me?

Oh, the accepted answer link is wrong! This is the right link.
When you use cmake,you must make sure you set ENABLE_BUILD_DYNAMIC to 1.
Here are my commandline on Windows:
cd gmsh_source_code_dir
mkdir build
cd build
cmake -DENABLE_BUILD_DYNAMIC=1 -DENABLE_FLTK=0 ..
cmake --build . --config Release
cmake --install .
You can find gmsh.lib and gmsh.dll in install directory. Then you can develop your software if you import lib or dll in your project.

The detailed instructions can be found at
https://gitlab.onelab.info/gmsh/gmsh/blob/master/demos/api/README.txt

Related

Installing FreeRDP on Mac OS without using Homebrew or full XCode [duplicate]

I can build my projects successfully with CMake, but can I use it to install the results?
With Make I add the target install and call that from the command line. I cannot figure out if this is possible with CMake.
The final goal is to install a static library, dynamic library and corresponding header files in a platform-portable way. How I imagine it would work: On Linux, copy to /usr/include and /usr/lib. On Windows it would probably be a user-provided folder with an include and lib folder.
The install rule suggests that something like this is possible. But how do I actually use it?
Currently I do the following:
mkdir build
cd build
cmake ..
cmake --build .
Here I would expect to do something like this:
cmake --install .
You can use the command cmake --build . --target install --config Debug for installation.
CMake's build tool mode supports further arguments that are of interest in this case.
You can select the target to build by --target option, the configuration to build by --config option, and pass arguments to the underlying build tool by means of the -- option. See the documentation (Build Tool Mode) for the build-tool-mode.
In CMake 3.15 and newer, you can use the simpler cmake --install command to Install a Project:
cmake --install . --config Debug
It additionally supports --prefix, --component and --strip.
You can use the install command on your CMakeLists that will generate installation rules for your project. A basic example is shown bellow but check the cmake documentation if you need something more complex.
project (Test)
add_executable(test main.cpp)
install(TARGETS test DESTINATION bin)
Then after generate the makefiles you can ust type sudo make install and the test application will be installed on system bin folder.

Differences between Apple LLVM and LLVM

I have Apple's command line tools version 9.1 installed and am working through an LLVM tutorial. I need to use some libraries like llvm/ADT and llvm/IR but get an error when I run the code.
main.cpp:1:10: fatal error: 'llvm/ADT/APFloat.h' file not found
#include "llvm/ADT/APFloat.h"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
I also don't seem to have tools such as the assembler. Are these things not usable with Apple's version? And can I install LLVM without conflicting with Apple's version?
Apple's fork misses most of the library,headers and command-line tools in the llvm trunk.
I suggest you compile a new llvm copy from trunk.
Conflicting depends on how you configure everything. You can:
Install your new copy to global location, where your $PATH configuration is responsible for choosing which version to use.
Install as a separate Xcode Toolchain.
Here is a build script I've been using:
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_APPEND_VC_REV=on -DLLVM_ENABLE_EH=on -DLLVM_ENABLE_RTTI=on -DLLVM_CREATE_XCODE_TOOLCHAIN=on -DCMAKE_INSTALL_PREFIX=~/Library/Developer/ ../LLVM
Running ninja install will install to global location, otherwise run ninja install-xcode-toolchain to install as a separate toolchain
In your case I suggest installing to global location to avoid the trouble of messing with CFLAGS/LDFLAGS/Header Search Path. Then remove the installation manually after you are done with the tutorial
EDIT: You might also want to check out the official build guide https://llvm.org/docs/CMake.html
For your use case, in-tree building is also a feasible option(Providing you are familiar with write cmake configs)
Actually, there is no need to build the LLVM yourself. You can get prebuilt version for your platform here: http://releases.llvm.org
In your case it would be something like this:
cd /opt
wget http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
tar xvf clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
mv clang+llvm-5.0.0-x86_64-apple-darwin llvm-5.0.0
After that you will have everything under /opt/llvm-5.0.0, e.g.:
/opt/llvm-5.0.0/bin/clang
/opt/llvm-5.0.0/bin/llvm-config
/opt/llvm-5.0.0/lib/libc++.a
etc.
P.S. I use /opt just as an example, feel free to pick any other directory that fits you best.

Firebreath Cmake not found when cmake 2.8.8 is installed on MacOsX

When trying to build an xcode project with the following command line:
./firebreath/prepmac.sh projects/ build/
I get:
Using projects in: /Users/uwecerron/Desktop/Node/projects
Generating build files in: /Users/uwecerron/Desktop/Node/build
NOTE: The build files in /Users/uwecerron/Desktop/Node/build should NEVER be modified directly. Make changes in cmake and re-run this script.
~/Desktop/Node/build ~/Desktop/Node
./firebreath/prepmac.sh: line 10: cmake: command not found
CMake failed. Please check error messages
There are no error messages, and i have cmake 2.8-8 installed. Any suggestions on what to do? this is for a kinect project using depthjs.
When you installed cmake it would have ask you if you wanted to install the command line links; you probably accidentally told it not to. Install cmake again and tell it to install the command-line links and it should work fine.

use MinGW to create exe file in windows from GNU source package

the basic idea was, I wanted to generate the call graph in text format for several c files. After googling around for long time, i found cflow, which can deliver everything I want, but it is only runable in Linux or else. Then I began to search how to compile the cflow source files on the web to a exe file. I found MinGW which should be able to do the cross-platform compilation.
After installing the MinGW and the MSYS and running the usual commands "./configure; make; make install", I simply got an error that "mkdir" was not found. Actually. Actually I was wondering whether this is the correct way to compile the whole package.
Does anyone has an idea how I can build the cflow.exe correctly in Windows? If there is a tutorial or something like this, I will be very thankful.
Song
Solution
Please try this Github repository "MinGW + MSYS build of GNU cflow 1.4" (For Windows).
https://github.com/noahp/cflow-mingw
It contains already compiled "cflow.exe",and an instruction about how to build cflow using mingw and msys.
Test
System Environment:Win 8.1 (x64)
1.I tested the "cflow.exe" downloaded from the github repository , and amazingly it worked!
2.I followed the mingw compiling instruction,and it successfully compiled "cflow 1.5".
Command:
bash configure
make
I was able to do that today. I'm using cygwin, after installing gcc, binutils, make and after downloading the gnu cflow.tar.gz, it was as easy as ./configure ; make ; make install.

How can I setup linux to compile FORTRAN code into windows binaries?

I'm working on a FORTRAN project and I would like to build all of the binaries that I want to maintain on a linux machine that is dedicated for automated builds. I have successfully used mingw to build 32-bit and 64-bit binaries from C source for windows machines on the linux machine with the following packages on Ubuntu.
apt-get install mingw32
apt-get install mingw-w64
Then I run the following commands to actually compile:
gcc -b amd64-mingw32msvc -V 4.4.4 -o <...other options>
However, the mingw packages that I've obtained via apt-get do not include FORTRAN compilers.
Anybody got any ideas on what I can do?
if you got mingw32 and the Gnu C cross compiler is working for you ... when why not just get the Gnu Fortran cross compiler, too?
http://www.nber.org/sys-admin/mingw32-fortran-fedora.html
EXAMPLE apt-get install mingw32-gcc-fortran
I know this is an old thread but a few things seem to have changed and people might still be interested in the topic.
Problem: I want to use my linux machine to compile some code and create a .exe that I can send to people using Windows.
Solution: Essentially here: http ://mxe.cc/
What I did:
Check to see if your system has all the software you need here
run
git clone -b stable https://github.com/mxe/mxe.git
It will download a few small things and create the directory "mxe" (probably in your home folder)
cd into that mxe directory and run "make". HOWEVER: this would take hours and take up a few GB on your hard drive so instead run something like
make mpfr eigen opencsg cgal qt
For more ideas on how to shorten that all see this or the mxe tutorial or somewhere else ;)
The easiest way to compile stuff then seems to be something like:
~/mxe/usr/bin/i686-pc-mingw32-gfortran -c main.f95
~/mxe/usr/bin/i686-pc-mingw32-gfortran main.o -o outfile.exe
Of course you can chose something other than fortran, just consult the mxe/usr/bin to see what its called.
You can always download and install a prebuilt compiler from the MinGW(-w64) project itself:
Windows 64-bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/rubenvb/4.6.2-1/
Windows 32-bit: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/rubenvb/4.6.2-1/
Just unpack somewhere and add the cross*/bin directory to PATH.
I include (obj)c(++) and fortran.
On Ubuntu 18.04 I use
apt install gfortran-mingw-w64
Then use the compiler x86_64-w64-mingw32-gfortran in place of gfortran. If you're using cmake, you can configure the compiler from the build directory like so:
FC=x86_64-w64-mingw32-gfortran cmake ..

Resources