* New to musl and C++ compiling
@ 2019-01-21 10:24 Michele Portolan
2019-01-21 11:53 ` Szabolcs Nagy
0 siblings, 1 reply; 5+ messages in thread
From: Michele Portolan @ 2019-01-21 10:24 UTC (permalink / raw)
To: musl
Hello,
I just installed MUSL because I have a C++ multithreaded application
that uses threads heavily and I would like to make it independent from
an OS. I was able to easily install and run MUSL for C targets, but when
I try a simple C++ Hello world I get an error for the standard libs.
My file is the simplest possible (no multithreading to start with):
#include <iostream>
int main() {
std::cout << "Hello, World" << std::endl;
return 0;
}
Here is my output for standard and musl-based compilation.
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"
test_cpp.cpp:1:11: fatal error: iostream: No such file or directory
#include <iostream>
^~~~~~~~~~
compilation terminated.
I am probably missing something REALLY basic, at least I hope so!
Best regards,
Michele
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: New to musl and C++ compiling
2019-01-21 10:24 New to musl and C++ compiling Michele Portolan
@ 2019-01-21 11:53 ` Szabolcs Nagy
2019-01-21 12:02 ` Szabolcs Nagy
0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2019-01-21 11:53 UTC (permalink / raw)
To: musl; +Cc: Michele Portolan
* Michele Portolan <michele.portolan@grenoble-inp.fr> [2019-01-21 11:24:12 +0100]:
> Hello,
>
> I just installed MUSL because I have a C++ multithreaded application that
> uses threads heavily and I would like to make it independent from an OS. I
> was able to easily install and run MUSL for C targets, but when I try a
> simple C++ Hello world I get an error for the standard libs.
>
> My file is the simplest possible (no multithreading to start with):
>
> #include <iostream>
>
> int main() {
> std::cout << "Hello, World" << std::endl;
> return 0;
> }
>
> Here is my output for standard and musl-based compilation.
>
> 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
g++ -v -E -xc++ - </dev/null
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.
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)
> test_cpp.cpp:1:11: fatal error: iostream: No such file or directory
> #include <iostream>
> ^~~~~~~~~~
> compilation terminated.
>
> I am probably missing something REALLY basic, at least I hope so!
>
> Best regards,
>
>
> Michele
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: New to musl and C++ compiling
2019-01-21 11:53 ` Szabolcs Nagy
@ 2019-01-21 12:02 ` Szabolcs Nagy
2019-01-21 13:13 ` Michele Portolan
0 siblings, 1 reply; 5+ messages in thread
From: Szabolcs Nagy @ 2019-01-21 12:02 UTC (permalink / raw)
To: musl, Michele Portolan
* Szabolcs Nagy <nsz@port70.net> [2019-01-21 12:53:13 +0100]:
> * Michele Portolan <michele.portolan@grenoble-inp.fr> [2019-01-21 11:24:12 +0100]:
> > Hello,
> >
> > I just installed MUSL because I have a C++ multithreaded application that
> > uses threads heavily and I would like to make it independent from an OS. I
> > was able to easily install and run MUSL for C targets, but when I try a
> > simple C++ Hello world I get an error for the standard libs.
> >
> > My file is the simplest possible (no multithreading to start with):
> >
> > #include <iostream>
> >
> > int main() {
> > std::cout << "Hello, World" << std::endl;
> > return 0;
> > }
> >
> > Here is my output for standard and musl-based compilation.
> >
> > 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
>
> g++ -v -E -xc++ - </dev/null
>
> 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.
>
> 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).
> > test_cpp.cpp:1:11: fatal error: iostream: No such file or directory
> > #include <iostream>
> > ^~~~~~~~~~
> > compilation terminated.
> >
> > I am probably missing something REALLY basic, at least I hope so!
> >
> > Best regards,
> >
> >
> > Michele
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: New to musl and C++ compiling
2019-01-21 12:02 ` Szabolcs Nagy
@ 2019-01-21 13:13 ` Michele Portolan
2019-01-21 13:55 ` Szabolcs Nagy
0 siblings, 1 reply; 5+ messages in thread
From: Michele Portolan @ 2019-01-21 13:13 UTC (permalink / raw)
To: musl
Thanks for the information.
You say "use a cross compiler that is built for musl" ... how do I do this?
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).
Thanks,
Michele
On 21/01/2019 13:02, Szabolcs Nagy wrote:
> * Szabolcs Nagy <nsz@port70.net> [2019-01-21 12:53:13 +0100]:
>
>> * Michele Portolan <michele.portolan@grenoble-inp.fr> [2019-01-21 11:24:12 +0100]:
>>> Hello,
>>>
>>> I just installed MUSL because I have a C++ multithreaded application that
>>> uses threads heavily and I would like to make it independent from an OS. I
>>> was able to easily install and run MUSL for C targets, but when I try a
>>> simple C++ Hello world I get an error for the standard libs.
>>>
>>> My file is the simplest possible (no multithreading to start with):
>>>
>>> #include <iostream>
>>>
>>> int main() {
>>> std::cout << "Hello, World" << std::endl;
>>> return 0;
>>> }
>>>
>>> Here is my output for standard and musl-based compilation.
>>>
>>> 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
>>
>> g++ -v -E -xc++ - </dev/null
>>
>> 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.
>>
>> 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).
>
>>> test_cpp.cpp:1:11: fatal error: iostream: No such file or directory
>>> #include <iostream>
>>> ^~~~~~~~~~
>>> compilation terminated.
>>>
>>> I am probably missing something REALLY basic, at least I hope so!
>>>
>>> Best regards,
>>>
>>>
>>> Michele
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: New to musl and C++ compiling
2019-01-21 13:13 ` Michele Portolan
@ 2019-01-21 13:55 ` Szabolcs Nagy
0 siblings, 0 replies; 5+ messages in thread
From: Szabolcs Nagy @ 2019-01-21 13:55 UTC (permalink / raw)
To: musl
* Michele Portolan <michele.portolan@grenoble-inp.fr> [2019-01-21 14:13:07 +0100]:
> Thanks for the information.
>
> You say "use a cross compiler that is built for musl" ... how do I do this?
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=x86_64-linux-musl install
and then use "output/bin/x86_64-linux-musl-g++ -static"
>
> 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).
>
> Thanks,
>
>
> Michele
>
> On 21/01/2019 13:02, Szabolcs Nagy wrote:
> > * Szabolcs Nagy <nsz@port70.net> [2019-01-21 12:53:13 +0100]:
> >
> > > * Michele Portolan <michele.portolan@grenoble-inp.fr> [2019-01-21 11:24:12 +0100]:
> > > > Hello,
> > > >
> > > > I just installed MUSL because I have a C++ multithreaded application that
> > > > uses threads heavily and I would like to make it independent from an OS. I
> > > > was able to easily install and run MUSL for C targets, but when I try a
> > > > simple C++ Hello world I get an error for the standard libs.
> > > >
> > > > My file is the simplest possible (no multithreading to start with):
> > > >
> > > > #include <iostream>
> > > >
> > > > int main() {
> > > > std::cout << "Hello, World" << std::endl;
> > > > return 0;
> > > > }
> > > >
> > > > Here is my output for standard and musl-based compilation.
> > > >
> > > > 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
> > >
> > > g++ -v -E -xc++ - </dev/null
> > >
> > > 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.
> > >
> > > 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).
> >
> > > > test_cpp.cpp:1:11: fatal error: iostream: No such file or directory
> > > > #include <iostream>
> > > > ^~~~~~~~~~
> > > > compilation terminated.
> > > >
> > > > I am probably missing something REALLY basic, at least I hope so!
> > > >
> > > > Best regards,
> > > >
> > > >
> > > > Michele
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-01-21 13:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-21 10:24 New to musl and C++ compiling Michele Portolan
2019-01-21 11:53 ` Szabolcs Nagy
2019-01-21 12:02 ` Szabolcs Nagy
2019-01-21 13:13 ` Michele Portolan
2019-01-21 13:55 ` Szabolcs Nagy
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).