Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c++ Subject: Re: Trying to be generic with the linker (ld instead of g++) Date: Thu, 22 Aug 2019 04:47:29 -0700 Organization: A noiseless patient Spider Lines: 39 Message-ID: <864l29ifqm.fsf@mailhub.linuxsc.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="59398aca864cd103291b848dd2e1e135"; logging-data="26432"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19WDoTPjOFiD6gyHh3Y3uez0RiVms/vUyw=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:g4/lXkRwgQLv0IzyOq2MLt8WfqQ= sha1:442YZEyA957J+YKCKZiKegMg+KQ= Xref: csiph.com comp.lang.c++:67869 Frederick Gotham writes: > I've been doing web searches all morning to try solve this so I'm > here now as last resort. > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Typically if we want to combine C and C++ in one program, we can > do three steps: > > gcc -c *.c > g++ -c *.cpp > g++ -o prog *.o > > So we use 'gcc' to compile the C code. Then we use 'g++' to compile > the C++ code. Finally we use 'g++' a second time to link the object > files together into one executable file. > > I'm trying to be as generic as possible here in the final step (i.e. > linking), and so I want to replace the second use of 'g++' with 'ld', > so something like: > > gcc -c *.c > g++ -c *.o > ld -o prog *.o > > [...] Forgive me if this is a dumb question. Is there some reason you have to use gcc in the first step? How about doing this instead: g++ -x c -c *.c g++ -x c++ -c *.cpp g++ -o prog *.o Substituting clang for g++ should also work here. Disclaimer: I haven't verified anything beyond confirming that both g++ and clang accept the -x c and -x c++ options.