Reputation: 11
I'm a C++ beginner and started learning about build systems. After looking for a more beginner-friendly system I came across Meson (CMake does not seem too appealing for a noob who just wants to throw a couple of files together). It looks pretty straightforward but as with most build systems (that I looked at) the documentation seems lacking in the sense that it assumes you already know how building works (which somehow reminds me of the chicken-egg problem).
I'm on a Windows 10 machine and use MSYS2 stack with MinGW64 and Meson installed as a package. I wrote some basic code to learn how to split it into multiple files for manageability. So I have a bare-bones project like this:
Cpp-App
I figured out how to include just the header file with include_directories() but I don't know how to link both of them. I also learned (kinda) how to build a library using those two, but not how to "use" it. For example, the program links and compiles successfully but when I run the program it says:
"error while loading shared libraries: libutils.dll: cannot open shared object file: No such file or directory"
although the resulting file is, in fact, inside the build directory.
Could you, please, guide me where to dig, and on a more fundamental note, where would a beginner learn stuff like this? Do I need to learn Make first before learning a modern build system? C++ books don't teach this, official docs and beginner tutorials show isolated and/or irrelevant examples =\
Main meson.build
project('cpp-app', 'cpp',
version : '0.1',
default_options : ['warning_level=3', 'cpp_std=c++14'])
subdir('./mylib')
myinc = include_directories ('./mylib')
executable('cpp-app',
'main.cpp',
include_directories : myinc,
link_with : mylib,
install : true)
meson.build for the library:
#project('utils', 'cpp')
mylib = library('utils', sources : ['utils.h', 'utils.cpp'])
Upvotes: 0
Views: 4155
Reputation: 11
So I finally was able to solve the problem. In this particular case you build the library from the main build file where you show it where the library files are (*.h and *.cpp). I removed meson.build from mylib folder and edited the main meson.build file like this:
project('cpp-app', 'cpp',
version : '0.1',
default_options : ['warning_level=3', 'cpp_std=c++14'])
myinc = include_directories ('mylib')
mylibpath = 'mylib/'
utilslib = shared_library('utils', sources : [mylibpath + 'utils.h', mylibpath + 'utils.cpp'])
executable('cpp-app',
'main.cpp',
include_directories : myinc,
link_with : utilslib,
install : true)
Upvotes: 1