Portable check for library - powershell

A project I am trying to compile has this command:
cc -xc++ -o/dev/null -lc++ -shared
However I am using PowerShell, which has no notion of /dev/null:
PS C:\> cc -xc++ -o/dev/null -lc++ -shared
C:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../
x86_64-w64-mingw32/bin/ld.exe: cannot open output file /dev/null.exe: No such
file or directory
I tried using -o$null, but it just creates a file $null.exe. I also tried this:
PS C:\> cc -xc++ -o $null -lc++ -shared
cc.exe: fatal error: no input files
Is PowerShell able to handle this use case? Alternatively, it seems the purpose of the test is to just check if libc++ exists. Is another way available to do that?

It appears the issue is specific to GCC. If I get Clang, the same command
works with nul:
cc -xc++ -onul -lc++ -shared
but if I try the same thing with GCC, I get this:
C:/msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../
x86_64-w64-mingw32/bin/ld.exe: nul.exe: final close failed: file truncated
I have posted bug 97574.

Related

Eclipse, Add all source file paths to an external tool as an argument

I would like to add an External Tool to my Eclipse CDT Project.
This external tool, which is a program that I have written myself, requires different arguments (the map file and a list of all *.c *.cpp and *.h files). I already managed to hand over the map file but is there any way of getting a list of all *.c and *.h files (maybe with an Eclipse Variable) so that I can directly add this to the argument field?
I found one solution which can be used on a linux system. Just use a a pipe with the following command and put it in a shell script.
First of all, how to find all source code files:
find <rootfolder> -name '*.c' -o -name '*.cpp' -o -name '*.h'
Complete command:
find <rootfolder> -name '*.c' -o -name '*.cpp' -o -name '*.h' | xargs <myTool>
The first command will find out all absolute paths to the all .c .cpp and .h files listed in the rootfolder and the second one will convert its input into a set on arguments. The result will be the same as if every found file path would have been handed over as a single argument to mytool.

cmake seems to not pick up my -DCMAKE_CXX_FLAGS

I have a totally simple setup. Two files in two separate directories.
mkdir a
touch a/a.h
mkdir b
echo '#include <a/a.h>' > b/b.c
Compiling works, when I specify a header path
cd b
gcc -c -I.. b.c
cd ..
OK now let's add cmake to the picture. For my purposes I need to specify the header search path via the command-line. Consider the CMakeLists.txt read only.
cat<<EOF > b/CMakeLists.txt
cmake_minimum_required (VERSION 3.0)
project (b)
add_library(b
b.c
)
EOF
mkdir b/build
cd b/build
cmake -DCMAKE_CXX_FLAGS=-I.. ..
make VERBOSE=1
But make fails and I don't see the -I.. specification in the cc command line.
[ 50%] Building C object CMakeFiles/b.dir/b.c.o
/Applications/Xcode.app/Contents/Developer/Toolchains /XcodeDefault.xctoolchain/usr/bin/cc -o CMakeFiles/b.dir/b.c.o -c /tmp/b/b.c
/tmp/b/b.c:1:10: fatal error: 'a/a.h' file not found
I tried giving an absolute path too, but it just doesn't work for me.
Your file has .c extension, you should use CMAKE_C_FLAGS for it.
And in most cases you should specify needed include search paths in CMakeLists.txt itself:
include_directories(..)

Adding text files to binaries with objcopy, but objcopy complains about architecture

I've read about embedding text files (or any other resource for that matter) into binaries, and I'm doing it like so:
objcopy -I binary -O elf32-littlearm --binary-architecture arm myfile.txt myfile.txt.o
However, unlike in the tutorial, I get the following response:
ld: unknown architecture of input file `myfile.txt' is incompatible with arm output
The example uses i386 but this doesn't seem to be the issue either as I can't do it that way either.
Is there a way I can force objcopy to ignore the fact it's a text file and not a valid compatible binary so it just copies it byte-for-byte into my program?
For data only object file (no code), you can skip binary-architecture option.
So the following should work
objcopy -I binary -O elf32-littlearm myfile.txt myfile.txt.o to generate object file.

How do i link 2 object files to form a binary file

I have tried using ld to link 2 .o files together with this,
ld -T link.ld -o kernel.bin kernel.o ks.o
but it produce an error saying
ld: cannot open linker script file link.ld: No such file or directory
Is there anything wrong with my commands or do i have to create a path or something?
You need to create the "linker script" link.ld. Google "linker script" for docs.

Definition of a symbol in a .so file on Solaris

Could somebody tell me how to find the definition of a symbol in a shared object file on Solaris.
Thanks
Raj
On the Solaris machines I have access to nm is available and can be used for this. For instance:
nm /usr/lib/libc.so
Shows all of the symbols in libc.so and then checking if a symbol is defined in this library is simply a matter of reading through the output.
Probably you want to pass the -g and -D options too for most cases. If you're looking to search a bunch of libraries you could try using:
find /usr/lib -name '*.so' -exec nm -gD {} \; |grep "symbol_name"
Or similar