As a learning exercise, I'm trying to build a kernel object file from a c file which would only do printk("hello, world") when loaded with modprobe. My kernel version is 4.15.
So let's say I have this example code:
int printk(const char *fmt, ...);
struct platform_device;
struct platform_driver {
int (*probe)(struct platform_device *);
int (*remove)(struct platform_device *);
};
static struct platform_driver my_driver = {
.probe = my_driver_probe,
.remove = my_driver_remove
};
module_platform_driver(my_driver);
static int my_driver_probe(struct platform_device *pdev) {
printk("my driver loaded\n");
return 0;
}
static int my_driver_remove(struct platform_device *pdev) {
printk("my driver removed\n");
return 0;
}
How do I compile it using gcc to create a valid my_driver.ko file that can be loaded with modprobe?
I'm trying to build a kernel object file from a c file which would only do printk("hello, world")
A short google search for such module resulted for me in the following examples: https://github.com/maK-/SimplestLKM https://github.com/moutoum/linux-kernel-module-hello-world https://github.com/ichergui/hello-world https://github.com/carloscdias/hello-world-linux-module .
How do I compile it using gcc to create a valid my_driver.ko file that can be loaded with modprobe?
The first project has the following source for a hello world module saved in hello.c:
#include<linux/init.h>
#include<linux/module.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("maK");
static int hello_init(void){
printk(KERN_ALERT "Hello world!\n");
return 0;
}
static void hello_exit(void){
printk(KERN_ALERT "Goodbye cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
The following is a transcript of a session with compiling the first project with V=1:
$ git clone https://github.com/maK-/SimplestLKM
Cloning into 'SimplestLKM'...
remote: Enumerating objects: 15, done.
remote: Total 15 (delta 0), reused 0 (delta 0), pack-reused 15
Receiving objects: 100% (15/15), 13.47 KiB | 431.00 KiB/s, done.
Resolving deltas: 100% (4/4), done.
$ cd SimplestLKM/
$ make V=1
make -C /lib/modules/5.10.72-1-lts/build M=/dev/shm/.1000.home.tmp.dir/SimplestLKM modules
make[1]: Entering directory '/usr/lib/modules/5.10.72-1-lts/build'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
make -f ./scripts/Makefile.build obj=/dev/shm/.1000.home.tmp.dir/SimplestLKM \
single-build= \
need-builtin=1 need-modorder=1
gcc -Wp,-MMD,/dev/shm/.1000.home.tmp.dir/SimplestLKM/.hello.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -fplugin=./scripts/gcc-plugins/structleak_plugin.so -fplugin-arg-structleak_plugin-byref-all -DSTRUCTLEAK_PLUGIN -DMODULE -DKBUILD_BASENAME='"hello"' -DKBUILD_MODNAME='"hello"' -c -o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.c
./tools/objtool/objtool orc generate --module --no-fp --retpoline --uaccess /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.o
{ echo /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.o; echo; } > /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.mod
{ echo /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.ko; :; } | awk '!x[$0]++' - > /dev/shm/.1000.home.tmp.dir/SimplestLKM/modules.order
make -f ./scripts/Makefile.modpost
sed 's/ko$/o/' /dev/shm/.1000.home.tmp.dir/SimplestLKM/modules.order | scripts/mod/modpost -a -o /dev/shm/.1000.home.tmp.dir/SimplestLKM/Module.symvers -e -i Module.symvers -N -T -
make -f ./scripts/Makefile.modfinal
gcc -Wp,-MMD,/dev/shm/.1000.home.tmp.dir/SimplestLKM/.hello.mod.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -fplugin=./scripts/gcc-plugins/structleak_plugin.so -fplugin-arg-structleak_plugin-byref-all -DSTRUCTLEAK_PLUGIN -DMODULE -DKBUILD_BASENAME='"hello.mod"' -DKBUILD_MODNAME='"hello"' -c -o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.mod.o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.mod.c
ld -r -m elf_x86_64 --build-id=sha1 -T scripts/module.lds -o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.ko /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.mod.o; true
make[1]: Leaving directory '/usr/lib/modules/5.10.72-1-lts/build'
From that we know that we also need the generated hello.mod.c. The content for this module as generated by modpost program is as follows:
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>
BUILD_SALT;
MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);
__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};
#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif
MODULE_INFO(depends, "");
MODULE_INFO(srcversion, "C7C2D304485DDC1C93263AE");
With both files in place, we can compile them with gcc, first to hello.o and hello.mod.o and then combine with ld. So these are the compiler flags needed to compile the module on my system:
( cd /usr/lib/modules/5.10.72-1-lts/build/ && gcc -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -fplugin=./scripts/gcc-plugins/structleak_plugin.so -fplugin-arg-structleak_plugin-byref-all -DSTRUCTLEAK_PLUGIN -DMODULE -DKBUILD_BASENAME='"hello"' -DKBUILD_MODNAME='"hello"' -c -o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.c )
( cd /usr/lib/modules/5.10.72-1-lts/build/ && gcc -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Wno-format-security -std=gnu89 -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -fno-jump-tables -fno-delete-null-pointer-checks -Wno-frame-address -Wno-format-truncation -Wno-format-overflow -Wno-address-of-packed-member -O2 -fno-allow-store-data-races -Wframe-larger-than=2048 -fstack-protector-strong -Wimplicit-fallthrough -Wno-unused-but-set-variable -Wno-unused-const-variable -g -gdwarf-4 -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -Wdeclaration-after-statement -Wvla -Wno-pointer-sign -Wno-stringop-truncation -Wno-zero-length-bounds -Wno-array-bounds -Wno-stringop-overflow -Wno-restrict -Wno-maybe-uninitialized -fno-strict-overflow -fno-stack-check -fconserve-stack -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wno-packed-not-aligned -fplugin=./scripts/gcc-plugins/structleak_plugin.so -fplugin-arg-structleak_plugin-byref-all -DSTRUCTLEAK_PLUGIN -DMODULE -DKBUILD_BASENAME='"hello"' -DKBUILD_MODNAME='"hello"' -c -o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.mod.o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.mod.c )
( cd /usr/lib/modules/5.10.72-1-lts/build/ && ld -r -m elf_x86_64 --build-id=sha1 -T scripts/module.lds -o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.ko /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.o /dev/shm/.1000.home.tmp.dir/SimplestLKM/hello.mod.o )
After that we can insmod hello.ko and have hello world printed with CRIT in dmesg.
what are the compiler flags to use in order to do it.
In the same fashion as presented above, you can find out what options are passed to the compiler on your system.
I am trying to build gcc for my linux. I'm cross compiling since I don't have a preexisting gcc.
I'm using musl as libc.
I configured gcc like this:
export CFLAGS="-pipe -march=native -fstack-protector-strong -fno-plt -pie -fpie"
../gcc-10.1.0/configure --target=x86_64-unknown-linux-musl \
--host=x86_64-unknown-linux-musl --build=x86_64-pc-linux-gnu \
--enable-lto --prefix=/usr --disable-nls --disable-multilib \
--enable-languages=c --without-isl --with-newlib --disable-libsanitizer \
--with-sysroot=/root/mnt
When I run make gcc compiles for a few minutes. After a while the build tries to execute the following
x86_64-unknown-linux-musl-gcc -O2 -g -O2 -pipe -march=native -fstack-protector-strong -fno-plt -pie -fpie -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -DUSE_ELF_SYMVER -DGTHREAD_USE_WEAK=0 -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -shared -nodefaultlibs -Wl,--soname=libgcc_s.so.1 -Wl,--version-script=libgcc.map -o ./libgcc_s.so.1.tmp -g -O2 -pipe -march=native -fstack-protector-strong -fno-plt -pie -fpie -B./ _muldi3_s.o _negdi2_s.o _lshrdi3_s.o _ashldi3_s.o _ashrdi3_s.o _cmpdi2_s.o _ucmpdi2_s.o _clear_cache_s.o _trampoline_s.o __main_s.o _absvsi2_s.o _absvdi2_s.o _addvsi3_s.o _addvdi3_s.o _subvsi3_s.o _subvdi3_s.o _mulvsi3_s.o _mulvdi3_s.o _negvsi2_s.o _negvdi2_s.o _ctors_s.o _ffssi2_s.o _ffsdi2_s.o _clz_s.o _clzsi2_s.o _clzdi2_s.o _ctzsi2_s.o _ctzdi2_s.o _popcount_tab_s.o _popcountsi2_s.o _popcountdi2_s.o _paritysi2_s.o _paritydi2_s.o _powisf2_s.o _powidf2_s.o _powixf2_s.o _mulhc3_s.o _mulsc3_s.o _muldc3_s.o _mulxc3_s.o _divhc3_s.o _divsc3_s.o _divdc3_s.o _divxc3_s.o _bswapsi2_s.o _bswapdi2_s.o _clrsbsi2_s.o _clrsbdi2_s.o _fixunssfsi_s.o _fixunsdfsi_s.o _fixunsxfsi_s.o _fixsfdi_s.o _fixdfdi_s.o _fixxfdi_s.o _fixunssfdi_s.o _fixunsdfdi_s.o _fixunsxfdi_s.o _floatdisf_s.o _floatdidf_s.o _floatdixf_s.o _floatundisf_s.o _floatundidf_s.o _floatundixf_s.o _divdi3_s.o _moddi3_s.o _divmoddi4_s.o _udivdi3_s.o _umoddi3_s.o _udivmoddi4_s.o _udiv_w_sdiv_s.o sfp-exceptions_s.o addtf3_s.o divtf3_s.o multf3_s.o negtf2_s.o subtf3_s.o unordtf2_s.o fixtfsi_s.o fixunstfsi_s.o floatsitf_s.o floatunsitf_s.o fixtfdi_s.o fixunstfdi_s.o floatditf_s.o floatunditf_s.o fixtfti_s.o fixunstfti_s.o floattitf_s.o floatuntitf_s.o extendsftf2_s.o extenddftf2_s.o extendxftf2_s.o trunctfsf2_s.o trunctfdf2_s.o trunctfxf2_s.o getf2_s.o letf2_s.o eqtf2_s.o _divtc3_s.o _multc3_s.o _powitf2_s.o enable-execute-stack_s.o unwind-dw2_s.o unwind-dw2-fde-dip_s.o unwind-sjlj_s.o unwind-c_s.o emutls_s.o libgcc.a -lc
in my build directory under x86_64-unknown-linux-musl/libgcc which fails with:
/root/mnt/tools/lib/gcc/x86_64-unknown-linux-musl/10.1.0/../../../../x86_64-unknown-linux-musl/bin/ld: /root/mnt/tools/lib/gcc/x86_64-unknown-linux-musl/10.1.0/../../../../x86_64-unknown-linux-musl/lib/Scrt1.o: in function `_start_c':
Scrt1.c:(.text._start_c+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
I verified with objdump -t crt1.o and objdump -t Scrt1.o that these object files define main, which they do.
Im pretty confused by now because the name libgcc suggests that it's a library, which of course does not have a main method. Why is ld expecting one? What is the build trying to do here?
I'm hoping for help installing Andreas Mueller's MATLAB bindings for Global Probability of Boundary.
I hope that my issue is not deeply ingrained in my installation, so I'll describe the immediate problem first, with the following paragraph noting some attempts at implementation.
According to Mueller's instructions in the readme, I did my best to install CUDA, ACML, and GCC (currently working on RHEL 7). After a successful build/install of the library libdamascene.so, I included a txt file in /etc/ld.so.conf.d/ which includes the path of libdamascene.so. It shows up when I use ldconfig -p | grep libdamascene.so.
When I open up MATLAB and try to build the MEX-file (using GCC 6.3) I get
Error using mex:
In file included from ../damascene-python-and-matlab-bindings-master/bindings/gpb_mex.c: 3: 0:
../damascene-python-and-matlab-bindings-master/bindings/gpb.h: 10: 143: error: expected ';', ',' or ')' before '=' token
void gpb(const unsigned int* in)image, unsigned int width, unsigned int height, float* border, int*textons, float* orientations, int device_num=0);
And a couple of subsequent errors that I gather are from the fact that the compiler wasn't able to properly read the header.
One thing I tried to do was to simply remove the declaration of device_num = 0 and place explicitly initialize it in the gpb_mex.c function call. This result is more nebulous.
Error using mex
/tmp/mex_1295917814264136_135235/gpb_mex.o: In function 'mexFunction':
gpb_mex.c: (.text+0x161): undefined reference to gpb
collect2: error: ld returned 1 exit status.
This error makes me thing that theres a problem with my library, which is a little more challenging to debug. I won't put all the things I tried (available on demand) to get a successful build of the library but let me summarize:
I'm running CUDA 9.0, not CUDA 8.0.
I'm running the gpuacml from the AMD Open64 SDK (only one I could find).
I had to change the gpu_architecture in the CMakelists.txt master file from sm_20 to sm_70.
I have a separate installation of GCC 6.3.0 (and GCC 5.3.0) so I can build the library.
My biggest question is: do you think this indeed a matter of an incorrectly built library or is there something else missing. Is there any way I can check if the library libdamascene.so is working correctly?
Please let me know how I can clarify my situation. Thank you so much!
Edit: I am including additional data.
Here's MATLAB output when I try to compile the MEX-file.
mex -v GCC='/usr/bin/gcc63' G++='/usr/bin/g++63' gpb_mex.c
Verbose mode is on.
... Looking for compiler 'gcc' ...
... Executing command 'which gcc' ...Yes ('/usr/bin/gcc').
... Executing command 'gcc -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-redhat-linux/4.8.5/libstdc++.so').
Found installed compiler 'gcc'.
Options file details
-------------------------------------------------------------------
Compiler location: /usr/bin/gcc63
Options file: /home/clusterbomb/.matlab/R2018b/mex_C_glnxa64.xml
CMDLINE2 : /usr/bin/gcc63 -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map" /tmp/mex_1326595352957888_135235/gpb_mex.o /tmp/mex_1326595352957888_135235/c_mexapi_version.o -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -o gpb_mex.mexa64
CC : /usr/bin/gcc63
DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fexceptions -fPIC -fno-omit-frame-pointer -pthread
INCLUDE : -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include"
COPTIMFLAGS : -O2 -fwrapv -DNDEBUG
CDEBUGFLAGS : -g
LD : /usr/bin/gcc63
LDFLAGS : -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64
LDTYPE : -shared
FUNCTIONMAP : "/usr/local/MATLAB/R2018b/extern/lib/glnxa64/mexFunction.map"
VERSIONMAP : "/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map"
LINKEXPORT : -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/mexFunction.map"
LINKEXPORTVER : -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map"
LINKLIBS : -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
MWCPPLIB : "/usr/local/MATLAB/R2018b/sys/os/glnxa64/libstdc++.so.6"
OBJEXT : .o
LDEXT : .mexa64
SETENV : CC="/usr/bin/gcc63"
CXX="g++"
CFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE "
CXXFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE "
COPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CXXOPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CDEBUGFLAGS="-g"
CXXDEBUGFLAGS="-g"
LD="/usr/bin/gcc63"
LDXX="g++"
LDFLAGS="-pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/mexFunction.map""
LDDEBUGFLAGS="-g"
GCC : /usr/bin/gcc63
CPPLIBS : /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libstdc++.so
MATLABROOT : /usr/local/MATLAB/R2018b
ARCH : glnxa64
SRC : "/home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex.c";"/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c"
OBJ : /tmp/mex_1326595352957888_135235/gpb_mex.o;/tmp/mex_1326595352957888_135235/c_mexapi_version.o
OBJS : /tmp/mex_1326595352957888_135235/gpb_mex.o /tmp/mex_1326595352957888_135235/c_mexapi_version.o
SRCROOT : /home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex
DEF : /tmp/mex_1326595352957888_135235/gpb_mex.def
EXP : "gpb_mex.exp"
LIB : "gpb_mex.lib"
EXE : gpb_mex.mexa64
ILK : "gpb_mex.ilk"
MANIFEST : "gpb_mex.mexa64.manifest"
TEMPNAME : gpb_mex
EXEDIR :
EXENAME : gpb_mex
G++ : /usr/bin/g++63
OPTIM : -O2 -fwrapv -DNDEBUG
LINKOPTIM : -O
CMDLINE1_0 : /usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex.c" -o /tmp/mex_1326595352957888_135235/gpb_mex.o
CMDLINE1_1 : /usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c" -o /tmp/mex_1326595352957888_135235/c_mexapi_version.o
-------------------------------------------------------------------
Building with 'gcc'.
/usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex.c" -o /tmp/mex_1326595352957888_135235/gpb_mex.o
/usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c" -o /tmp/mex_1326595352957888_135235/c_mexapi_version.o
/usr/bin/gcc63 -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map" /tmp/mex_1326595352957888_135235/gpb_mex.o /tmp/mex_1326595352957888_135235/c_mexapi_version.o -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -o gpb_mex.mexa64
Error using mex
/tmp/mex_1326595352957888_135235/gpb_mex.o: In function `mexFunction':
gpb_mex.c:(.text+0x161): undefined reference to `gpb'
collect2: error: ld returned 1 exit status
Here's the header file gpb.h (with edit of removing device_num=0):
void gpb(const unsigned int* in_image,unsigned int width,unsigned int height, float* border, int* textons, float* orientations, int device_num);
Here's the gpb_mex.c file with the alteration of addition the declared device_num in the final line:
#include <mex.h>
#include "gpb.h"
void mexFunction(int nOut, mxArray *pOut[],
int nIn, const mxArray *pIn[])
{
mwSize width, height;
float* borders;
float* orientations;
int* textons;
unsigned int *in_image;
mwSize dims[3];
mwSize orientation_dims[3];
if((nIn != 1) || (nOut != 3))
mexErrMsgTxt("Usage: border,textons,orientations = gpb(image)");
if (!mxIsClass(pIn[0],"uint8") || mxGetNumberOfDimensions(pIn[0]) != 3) {
mexErrMsgTxt("Usage: th argument must be a unsigned int matrix");
}
const mwSize *indims= mxGetDimensions(pIn[0]);
if (indims[0]!=4)
mexErrMsgTxt("Image needs to be of shape 4 x widht x height");
width = indims[2];
height = indims[1];
mexPrintf("width %d, height %d\n",width,height);
mexPrintf("Element-size: %d, sizeof(int): %d, sizeof(char) %d\n",mxGetElementSize(pIn[0]),sizeof(int),sizeof(unsigned char));
dims[0]=width; dims[1]=height; //for rgb0
mexPrintf("width: %d height: %d\n",width, height);
pOut[0]=mxCreateNumericMatrix(height,width,mxSINGLE_CLASS,mxREAL);
pOut[1]=mxCreateNumericMatrix(height,width,mxINT32_CLASS,mxREAL);
orientation_dims[0]=width; orientation_dims[1]=height; orientation_dims[2]=8;
pOut[2]=mxCreateNumericArray(3,orientation_dims,mxSINGLE_CLASS,mxREAL);
borders=(float*) mxGetPr(pOut[0]);
textons=(int*) mxGetPr(pOut[1]);
orientations=(float*) mxGetPr(pOut[2]);
in_image = (unsigned int*) mxGetData(pIn[0]);
gpb(in_image,height,width,borders,textons,orientations, 0);
}
Happy to provide any more source code as need, but the rest would be ripped straight from amueller's repository (link above).
Edit 2:
using -L resulted in a permission error, which I resolved by sudo chmod 755 libdamascene.so in linux terminal.
So the good news is that matlab was able to find libdamascene, evidenced by it moving forward after permission denied. Unfortunately, the compiler is still struggling.
mex -v GCC='/usr/bin/gcc63' gpb_mex.c -L</home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/build/libdamascene.so>
Verbose mode is on.
... Looking for compiler 'gcc' ...
... Executing command 'which gcc' ...Yes ('/usr/bin/gcc').
... Executing command 'gcc -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-redhat-linux/4.8.5/libstdc++.so').
Found installed compiler 'gcc'.
Options file details
-------------------------------------------------------------------
Compiler location: /usr/bin/gcc63
Options file: /home/clusterbomb/.matlab/R2018b/mex_C_glnxa64.xml
CMDLINE2 : /usr/bin/gcc63 -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map" /tmp/mex_1363958469865432_171081/gpb_mex.o /tmp/mex_1363958469865432_171081/c_mexapi_version.o -L</home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/build/libdamascene.so> -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -o gpb_mex.mexa64
CC : /usr/bin/gcc63
DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fexceptions -fPIC -fno-omit-frame-pointer -pthread
INCLUDE : -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include"
COPTIMFLAGS : -O2 -fwrapv -DNDEBUG
CDEBUGFLAGS : -g
LD : /usr/bin/gcc63
LDFLAGS : -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64
LDTYPE : -shared
FUNCTIONMAP : "/usr/local/MATLAB/R2018b/extern/lib/glnxa64/mexFunction.map"
VERSIONMAP : "/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map"
LINKEXPORT : -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/mexFunction.map"
LINKEXPORTVER : -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map"
LINKLIBS : -L</home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/build/libdamascene.so> -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
MWCPPLIB : "/usr/local/MATLAB/R2018b/sys/os/glnxa64/libstdc++.so.6"
OBJEXT : .o
LDEXT : .mexa64
SETENV : CC="/usr/bin/gcc63"
CXX="g++"
CFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE "
CXXFLAGS="-fexceptions -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE "
COPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CXXOPTIMFLAGS="-O2 -fwrapv -DNDEBUG"
CDEBUGFLAGS="-g"
CXXDEBUGFLAGS="-g"
LD="/usr/bin/gcc63"
LDXX="g++"
LDFLAGS="-pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -L</home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/build/libdamascene.so> -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/mexFunction.map""
LDDEBUGFLAGS="-g"
GCC : /usr/bin/gcc63
CPPLIBS : /usr/lib/gcc/x86_64-redhat-linux/4.8.5/libstdc++.so
MATLABROOT : /usr/local/MATLAB/R2018b
ARCH : glnxa64
SRC : "/home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex.c";"/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c"
OBJ : /tmp/mex_1363958469865432_171081/gpb_mex.o;/tmp/mex_1363958469865432_171081/c_mexapi_version.o
OBJS : /tmp/mex_1363958469865432_171081/gpb_mex.o /tmp/mex_1363958469865432_171081/c_mexapi_version.o
SRCROOT : /home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex
DEF : /tmp/mex_1363958469865432_171081/gpb_mex.def
EXP : "gpb_mex.exp"
LIB : "gpb_mex.lib"
EXE : gpb_mex.mexa64
ILK : "gpb_mex.ilk"
MANIFEST : "gpb_mex.mexa64.manifest"
TEMPNAME : gpb_mex
EXEDIR :
EXENAME : gpb_mex
OPTIM : -O2 -fwrapv -DNDEBUG
LINKOPTIM : -O
CMDLINE1_0 : /usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex.c" -o /tmp/mex_1363958469865432_171081/gpb_mex.o
CMDLINE1_1 : /usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c" -o /tmp/mex_1363958469865432_171081/c_mexapi_version.o
-------------------------------------------------------------------
Building with 'gcc'.
/usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/bindings/gpb_mex.c" -o /tmp/mex_1363958469865432_171081/gpb_mex.o
/usr/bin/gcc63 -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -D_GNU_SOURCE -DMATLAB_MEX_FILE -I"/usr/local/MATLAB/R2018b/extern/include" -I"/usr/local/MATLAB/R2018b/simulink/include" -fexceptions -fPIC -fno-omit-frame-pointer -pthread -O2 -fwrapv -DNDEBUG "/usr/local/MATLAB/R2018b/extern/version/c_mexapi_version.c" -o /tmp/mex_1363958469865432_171081/c_mexapi_version.o
/usr/bin/gcc63 -pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2018b/bin/glnxa64 -shared -O -Wl,--version-script,"/usr/local/MATLAB/R2018b/extern/lib/glnxa64/c_exportsmexfileversion.map" /tmp/mex_1363958469865432_171081/gpb_mex.o /tmp/mex_1363958469865432_171081/c_mexapi_version.o -L</home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/build/libdamascene.so> -L"/usr/local/MATLAB/R2018b/bin/glnxa64" -lmx -lmex -lmat -lm -lstdc++ -o gpb_mex.mexa64
/tmp/mex_1363958922594243_171081: line 2: -L/usr/local/MATLAB/R2018b/bin/glnxa64: No such file or directory
Error using mex
The command '/usr/bin/gcc63' exited with a return value '1'
I have double and triple checked that the directory /usr/local/MATLAB/R2018b/bin/glnxa64 exists (it does). I have also tried restoredefaultpath and rehash toolboxcache to no avail. No change when I utilize gcc 5.3.0 or the native RHEL 7 gcc. Thank you for your help so far!
In the file damascene-python-and-matlab-bindings/bindings/gpb.h, the following line causes the error:
void gpb(const unsigned int* in_image,unsigned int width,unsigned int height, float* border, int* textons, float* orientations, int device_num=0);
The last argument has a default parameter, which is a C++ feature, an not valid C syntax. Remove the =0 so it becomes:
void gpb(const unsigned int* in_image,unsigned int width,unsigned int height, float* border, int* textons, float* orientations, int device_num);
Next, when you call gpb, you cannot rely on the default value for device_num, so you need to pass this explicitly. In damascene-python-and-matlab-bindings/bindings/gpb_mex.c, the line:
gpb(in_image,height,width,borders,textons,orientations);
needs an additional argument 0:
gpb(in_image,height,width,borders,textons,orientations,0);
With these changes, I hope, the code should compile normally with a C compiler.
(I realize that you already did these things...)
Finally, the linker needs to find the gpb function. I presume this one is in the libdamascene.so library that you built. You need to tell the mex command to link in this library:
mex -v GCC='/usr/bin/gcc63' gpb_mex.c -ldamascene
(the argument to -l gets lib prepended and .a or .so appended, to form the name of the library file. Depending on where this library file resides, you might need to also add a -L<path> argument to the mex call, with <path> the directory that contains the library file:
mex -v GCC='/usr/bin/gcc63' gpb_mex.c -L/home/clusterbomb/Downloads/GPUGPB/damascene-python-and-matlab-bindings-master/build/libdamascene.so
I am using NDK standalone toolchain to build a dynamic library(.so) on Mac OS.
I just migrate the C language compiler from GCC to clang.When using GCC the processes are all OK and so file is generated successfully. But when using clang,some errors happen when issue ./configure.The errors are as follows.
The picture error logs:
The text error logs,it is the same with the above picture error logs:
check_as
BEGIN /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
1 .altmacro
END /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
arm-linux-androideabi-clang -D_ISOC99_SOURCE -Dstrtod=avpriv_strtod -I$(SRC_PATH)/compat/float -DPIC -O3 -Wall -pipe -std=c99 -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID -DNDEBUG -I/Users/zexu/github/ijkplayer/android/contrib/build/openssl-armv7a/output/include -march=armv7-a -mcpu=cortex-a8 -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -mcpu=cortex-a8 -fPIC -c -o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.DIksqWpw.o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option]
1 warning generated.
/var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S:1:1: error: unknown directive
.altmacro
^
check_gas using 'arm-linux-androideabi-clang' as AS
check_as
BEGIN /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
1 .macro m n, y:vararg=0
2 \n: .int \y
3 .endm
4 m x
END /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
arm-linux-androideabi-clang -D_ISOC99_SOURCE -Dstrtod=avpriv_strtod -I$(SRC_PATH)/compat/float -DPIC -O3 -Wall -pipe -std=c99 -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID -DNDEBUG -I/Users/zexu/github/ijkplayer/android/contrib/build/openssl-armv7a/output/include -march=armv7-a -mcpu=cortex-a8 -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -mcpu=cortex-a8 -fPIC -c -o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.DIksqWpw.o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option]
1 warning generated.
check_as
BEGIN /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
1 .altmacro
END /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
arm-linux-androideabi-clang -D_ISOC99_SOURCE -Dstrtod=avpriv_strtod -I$(SRC_PATH)/compat/float -DPIC -O3 -Wall -pipe -std=c99 -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID -DNDEBUG -I/Users/zexu/github/ijkplayer/android/contrib/build/openssl-armv7a/output/include -march=armv7-a -mcpu=cortex-a8 -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -mcpu=cortex-a8 -fPIC -c -o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.DIksqWpw.o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S
warning: unknown warning option '-Wno-psabi' [-Wunknown-warning-option]
1 warning generated.
/var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.t5WIvSJ0.S:1:1: error: unknown directive
.altmacro
^
GNU assembler not found, install/update gas-preprocessor
The toolchain configurations in the configure file:
# toolchain
ar_default="ar"
cc_default="clang"
cxx_default="clang++"
host_cc_default="clang"
cp_f="cp -f"
doxygen_default="doxygen"
install="install"
ln_s_default="ln -s -f"
nm_default="nm -g"
objformat="elf"
pkg_config_default=pkg-config
ranlib_default="ranlib"
strip_default="strip"
version_script='--version-script'
yasmexe_default="yasm"
windres_default="windres"
The NDK version is r14b,and the clang version:
Android clang version 3.8.275480 (based on LLVM 3.8.275480)
Target: x86_64-apple-darwin17.2.0
Thread model: posix
I know that the error is not caused by the "gas-preprocessor",because GCC compiler also has this problem.The GCC logs with no errors:
check_cc
BEGIN /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.51pLIKDT.c
1 unsigned int endian = 'B' << 24 | 'I' << 16 | 'G' << 8 | 'E';
END /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.51pLIKDT.c
arm-linux-androideabi-gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Dstrtod=avpriv_strtod -DPIC -O3 -Wall -pipe -std=c99 -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID -DNDEBUG -I/Users/zexu/github/ijkplayer/android/contrib/build/openssl-armv7a/output/include -march=armv7-a -mcpu=cortex-a8 -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -mcpu=cortex-a8 -std=c11 -fomit-frame-pointer -fPIC -c -o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.bcyz1Buv.o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.51pLIKDT.c
gas-preprocessor.pl -arch arm -as-type gas -- arm-linux-androideabi-gcc -v
./configure: line 883: gas-preprocessor.pl: command not found
check_gas using 'arm-linux-androideabi-gcc' as AS
check_as
BEGIN /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.QeTKRayl.S
1 .macro m n, y:vararg=0
2 \n: .int \y
3 .endm
4 m x
END /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.QeTKRayl.S
arm-linux-androideabi-gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Dstrtod=avpriv_strtod -DPIC -O3 -Wall -pipe -std=c99 -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID -DNDEBUG -I/Users/zexu/github/ijkplayer/android/contrib/build/openssl-armv7a/output/include -march=armv7-a -mcpu=cortex-a8 -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -mcpu=cortex-a8 -fPIC -c -o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.bcyz1Buv.o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.QeTKRayl.S
check_as
BEGIN /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.QeTKRayl.S
1 .altmacro
END /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.QeTKRayl.S
arm-linux-androideabi-gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Dstrtod=avpriv_strtod -DPIC -O3 -Wall -pipe -std=c99 -ffast-math -fstrict-aliasing -Werror=strict-aliasing -Wno-psabi -Wa,--noexecstack -DANDROID -DNDEBUG -I/Users/zexu/github/ijkplayer/android/contrib/build/openssl-armv7a/output/include -march=armv7-a -mcpu=cortex-a8 -mfpu=vfpv3-d16 -mfloat-abi=softfp -mthumb -mcpu=cortex-a8 -fPIC -c -o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.bcyz1Buv.o /var/folders/k6/bsgr75lj6j99fl0q8ygrr7840000gn/T//ffconf.QeTKRayl.S
Anyone can give me some tips?
Issues with assembler when switching from GCC to Clang are usually fixed with -fno-integrated-as. Clang has a built in assembler that it uses for assembling generating code that is not 100% compatible with GNU's assembler. If you have any inline assembly, you will either need to update that assembly to be compatible with LLVM's assembler or pass -fno-integrated-as to instruct Clang to use GNU as instead.
I am trying to build my own lfs system for Raspberry PI 2.
As a part of it I am trying to compile gcc on Raspberry PI 2, with raspbian as a base operating system.
I could build the binutils using the instructions on lfs development version. But while compiling gcc I am getting below error
g++ -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I../../gcc-5.2.0/gcc -I../../gcc-5.2.0/gcc/. -I../../gcc-5.2.0/gcc/../include -I../../gcc-5.2.0/gcc/../libcpp/include -I/mnt/lfs/sources/gcc-build/./gmp -I/mnt/lfs/sources/gcc-5.2.0/gmp -I/mnt/lfs/sources/gcc-build/./mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpc/src -I../../gcc-5.2.0/gcc/../libdecnumber -I../../gcc-5.2.0/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc-5.2.0/gcc/../libbacktrace -o except.o -MT except.o -MMD -MP -MF ./.deps/except.TPo ../../gcc-5.2.0/gcc/except.c
g++ -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I../../gcc-5.2.0/gcc -I../../gcc-5.2.0/gcc/. -I../../gcc-5.2.0/gcc/../include -I../../gcc-5.2.0/gcc/../libcpp/include -I/mnt/lfs/sources/gcc-build/./gmp -I/mnt/lfs/sources/gcc-5.2.0/gmp -I/mnt/lfs/sources/gcc-build/./mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpc/src -I../../gcc-5.2.0/gcc/../libdecnumber -I../../gcc-5.2.0/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc-5.2.0/gcc/../libbacktrace -o explow.o -MT explow.o -MMD -MP -MF ./.deps/explow.TPo ../../gcc-5.2.0/gcc/explow.c
g++ -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I../../gcc-5.2.0/gcc -I../../gcc-5.2.0/gcc/. -I../../gcc-5.2.0/gcc/../include -I../../gcc-5.2.0/gcc/../libcpp/include -I/mnt/lfs/sources/gcc-build/./gmp -I/mnt/lfs/sources/gcc-5.2.0/gmp -I/mnt/lfs/sources/gcc-build/./mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpc/src -I../../gcc-5.2.0/gcc/../libdecnumber -I../../gcc-5.2.0/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc-5.2.0/gcc/../libbacktrace -o expmed.o -MT expmed.o -MMD -MP -MF ./.deps/expmed.TPo ../../gcc-5.2.0/gcc/expmed.c
../../gcc-5.2.0/gcc/wide-int.h: In function 'long long unsigned int choose_multiplier(long long unsigned int, int, int, long long unsigned int*, int*, int*)':
../../gcc-5.2.0/gcc/wide-int.h:798:57: warning: array subscript is below array bounds [-Warray-bounds]
../../gcc-5.2.0/gcc/wide-int.h:798:57: warning: array subscript is below array bounds [-Warray-bounds]
g++ -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I../../gcc-5.2.0/gcc -I../../gcc-5.2.0/gcc/. -I../../gcc-5.2.0/gcc/../include -I../../gcc-5.2.0/gcc/../libcpp/include -I/mnt/lfs/sources/gcc-build/./gmp -I/mnt/lfs/sources/gcc-5.2.0/gmp -I/mnt/lfs/sources/gcc-build/./mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpfr/src -I/mnt/lfs/sources/gcc-5.2.0/mpc/src -I../../gcc-5.2.0/gcc/../libdecnumber -I../../gcc-5.2.0/gcc/../libdecnumber/dpd -I../libdecnumber -I../../gcc-5.2.0/gcc/../libbacktrace -o expr.o -MT expr.o -MMD -MP -MF ./.deps/expr.TPo ../../gcc-5.2.0/gcc/expr.c
../../gcc-5.2.0/gcc/expr.c: In function 'void store_constructor(tree, rtx, int, long long int)':
../../gcc-5.2.0/gcc/expr.c:6529:1: internal compiler error: output_operand: invalid shift operand
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
Preprocessed source stored into /tmp/ccAUc9Pu.out file, please attach this to your bugreport.
Makefile:1065: recipe for target 'expr.o' failed
make[2]: *** [expr.o] Error 1
make[2]: Leaving directory '/mnt/lfs/sources/gcc-build/gcc'
Makefile:4105: recipe for target 'all-gcc' failed
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory '/mnt/lfs/sources/gcc-build'
Makefile:858: recipe for target 'all' failed
make: *** [all] Error 2
I tried to trace the cause of error by looking at the expr.c file, but could not find issue. I have uploaded the "/tmp/ccAUc9Pu.out" to http://turl.ca/dcfansr
Can someone please help me how to debug the exact cause of issue
I had the same problem after checking all the system requirements were installed by running the version check at http://www.linuxfromscratch.org/lfs/view/stable-systemd/prologue/hostreqs.html and rebooting the system it worked afterwards.