From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/13632 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: New to musl and C++ compiling Date: Mon, 21 Jan 2019 14:55:54 +0100 Message-ID: <20190121135554.GT21289@port70.net> References: <20190121115313.GR21289@port70.net> <20190121120224.GS21289@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: ciao.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ciao.gmane.org 1548078965 191649 195.159.176.228 (21 Jan 2019 13:56:05 GMT) X-Complaints-To: usenet@ciao.gmane.org NNTP-Posting-Date: Mon, 21 Jan 2019 13:56:05 +0000 (UTC) User-Agent: Mutt/1.10.1 (2018-07-13) To: musl@lists.openwall.com Original-X-From: musl-return-13648-gllmg-musl=m.gmane.org@lists.openwall.com Mon Jan 21 14:55:58 2019 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by ciao.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1gla3S-000nha-CD for gllmg-musl@m.gmane.org; Mon, 21 Jan 2019 14:55:58 +0100 Original-Received: (qmail 17906 invoked by uid 550); 21 Jan 2019 13:56:06 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 17888 invoked from network); 21 Jan 2019 13:56:05 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:13632 Archived-At: * Michele Portolan [2019-01-21 14:13:07 = +0100]: > Thanks for the information. >=20 > You say "use a cross compiler that is built for musl" ... how do I do thi= s? build gcc for x86_64-linux-musl target, there are some subtleties, so it may be easier to use an existing build script such as https://github.com/richfelker/musl-cross-make and then make -j$(nproc) TARGET=3Dx86_64-linux-musl install and then use "output/bin/x86_64-linux-musl-g++ -static" >=20 > Binaries are useful, but if I can also get the build process right it is > more powerful, and easier to pass to students (I am an academic). >=20 > Thanks, >=20 >=20 > Michele >=20 > On 21/01/2019 13:02, Szabolcs Nagy wrote: > > * Szabolcs Nagy [2019-01-21 12:53:13 +0100]: > >=20 > > > * Michele Portolan [2019-01-21 11:= 24:12 +0100]: > > > > Hello, > > > >=20 > > > > I just installed MUSL because I have a C++ multithreaded applicatio= n that > > > > uses threads heavily and I would like to make it independent from a= n OS. I > > > > was able to easily install and run MUSL for C targets, but when I t= ry a > > > > simple C++ Hello world I get an error for the standard libs. > > > >=20 > > > > My file is the simplest possible (no multithreading to start with): > > > >=20 > > > > =C2=A0#include > > > >=20 > > > > =C2=A0int main() { > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 std::cout <= < "Hello, World" << std::endl; > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return 0; > > > > } > > > >=20 > > > > Here is my output for standard and musl-based compilation. > > > >=20 > > > > portolan@noumea:~/musl/examples$ g++ -o test_cpp test_cpp.cpp > > > > portolan@noumea:~/musl/examples$ ./test_cpp > > > > Hello, World > > > > portolan@noumea:~/musl/examples$ g++ -o test_cpp test_cpp.cpp -specs > > > > "/home/portolan/musl/install/lib/musl-gcc.specs" > > > for c++ the recommended practice is to use a cross compiler that > > > is built for musl, instead of a glibc based native compiler with > > > a specs file or other wrapping mechanism, because c++ headers are > > > difficult to get right: in this case the specs file disabled all > > > c++ header paths, you need to add those back manually, see > > >=20 > > > g++ -v -E -xc++ - > >=20 > > > but there may be still issues > > > - the header ordering matters as libstdc++ uses include_next and > > > - some headers are installed based on the libc found at configure > > > time of gcc, so the abi is slightly different depending on what > > > libc you built your compiler for, > > > - e.g. with static linking (which you need if you want a portable > > > executable) one issue is that libstdc++ has a broken way to > > > detect multi-threadedness and all locks become nops (unless your > > > binary has a definition for the 'pthread_cancel' symbol). > > > if gcc is configured for *-musl* this is fixed. > > >=20 > > > in short: use a cross compiler targetting *-linux-musl, there are > > > prebuilt ones at http://musl.cc/ > > > (note that you will have to build and install all your application > > > dependencies into a path where the cross compiler can find them) > > oh and if you have many dependencies then the simplest way is of > > course to use a musl based distro (alpine, void, adelie,..) then > > you can use all the prebuilt packages and the native toolchain > > with g++ -static and you get a portable executable. > > (setting up a chroot or docker with whatever distro should not be > > too much work). > >=20 > > > > test_cpp.cpp:1:11: fatal error: iostream: No such file or directory > > > > =C2=A0 #include > > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ^~~~~= ~~~~~ > > > > compilation terminated. > > > >=20 > > > > I am probably missing something REALLY basic, at least I hope so! > > > >=20 > > > > Best regards, > > > >=20 > > > >=20 > > > > Michele