When I try to complile the dhrystone benchmark, it shows the following errors:
xilinx#pynq:~/dhrystone$ riscv32-unknown-elf-gcc -Os -ffreestanding -nostdlib -o out.elf -Wl,-Bstatic,-T,picorv32.ld dhry_1.o dhry_2.o init.o -lgcc -march=rv32im
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.o: in function `Proc_1':
dhry_1.c:(.text+0x84): undefined reference to `memcpy'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text+0x100): undefined reference to `memcpy'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.o: in function `main':
dhry_1.c:(.text.startup+0x3c): undefined reference to `malloc'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text.startup+0x4c): undefined reference to `malloc'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text.startup+0x84): undefined reference to `strcpy'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text.startup+0x98): undefined reference to `strcpy'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text.startup+0xb8): undefined reference to `time'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text.startup+0xf0): undefined reference to `strcpy'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text.startup+0x184): undefined reference to `time'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_1.c:(.text.startup+0x254): undefined reference to `strcpy'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: dhry_2.o: in function `.L15':
dhry_2.c:(.text+0x118): undefined reference to `strcmp'
collect2: error: ld returned 1 exit status
It seems that all the missing functions are from stdih.h. But I don't know how to fix it.
heres the commands I used to compile the benchmark.
riscv32-unknown-elf-gcc -c -Qn -DSTKPTR=32768 -march=rv32im -o init.o -Os --std=c99 init.S
riscv32-unknown-elf-gcc -c -Qn -march=rv32im -o dhry_1.o -Os --std=c99 dhry_1.c
riscv32-unknown-elf-gcc -c -Qn -march=rv32im -o dhry_2.o -Os --std=c99 dhry_2.c
riscv32-unknown-elf-gcc -Os -ffreestanding -nostdlib -o out.elf -Wl,-Bstatic,-T,picorv32.ld init.o dhry_1.o dhry_2.o -lgcc -march=rv32im
riscv32-unknown-elf-objcopy -O binary out.elf out.bin
Can anyone help me pls. Thanks for any help.
With the help of #yflelion, i've changed the fifth line to the following,
riscv32-unknown-elf-gcc -Os -ffreestanding -nostdlib -o out.elf -Wl,-Bstatic,-T,picorv32.ld init.o dhry_1.o dhry_2.o -lgcc -lc -lgloss -march=rv32im
And it shows the following errors,
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: /opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/lib/libgloss.a(sys_gettimeofday.o): in function `.L5':
sys_gettimeofday.c:(.text+0x48): undefined reference to `__errno'
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: /opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/lib/libgloss.a(sys_sbrk.o): in function `.L7':
sys_sbrk.c:(.text+0x84): undefined reference to `__errno'
collect2: error: ld returned 1 exit status
with the following command,
riscv32-unknown-elf-gcc -Os -ffreestanding -nostdlib -o out.elf -Wl,-Bstatic,-T,picorv32.ld init.o dhry_1.o dhry_2.o -lgcc -lc -march=rv32im
it shows the following errors,
/opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/bin/ld: /opt/riscv32im/lib/gcc/riscv32-unknown-elf/10.1.0/../../../../riscv32-unknown-elf/lib/libc.a(lib_a-sbrkr.o): in function `_sbrk_r':
sbrkr.c:(.text+0x20): undefined reference to `_sbrk'
When you use nostdlib, the compiler not use the standard system startup files or libraries when linking.
https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
The only library you are linking against by using your command line is libgcc, but you are using functions from libc. you need to add -lc and most likely -lgloss. be careful with circular dependencies ( --start-group --end-group).
You can add the -v option and compile a minimalist example with the default options to see how it is done by default.
If there is no reason why you cannot use libc and libgloss by default, it is better to remove nostdlib option.
To compile your example try:
riscv32-unknown-elf-gcc -Os -ffreestanding -nostdlib -o out.elf -Wl,-Bstatic,-T,picorv32.ld init.o dhry_1.o dhry_2.o -lgcc -lc -lgloss -lc -march=rv32im
But the best solution to avoid circular dependencies would be:
riscv32-unknown-elf-gcc -Os -ffreestanding -nostdlib -o out.elf -Wl,-Bstatic,-T,picorv32.ld init.o dhry_1.o dhry_2.o -lgcc --start-group -lc -lgloss --end-group -lgcc -march=rv32im
Related
I am in my first compilation using the accelerometer_app example. Ninja crashes in step 1. It seems to be due to a problem with the linking process. Here is the output.
PS G:\Cardiovelo_sur_NAS\Laboratoires\Labo_TI\Labo_Movesense\movesense-device-lib\myBuild> ninja
[1/1] Linking CXX executable Movesense
FAILED: Movesense
cmd.exe /C "cd . && C:\PROGRA~2\GNUTOO~1\92019-~1\bin\AR19DD~1.EXE -W -Wall -Werror -Wfatal-errors -Wshadow -Wpointer-arith -Wcast-qual -Wwrite-strings -Wunreachable-code -Wsign-compare -Wno-aggregate-return -Wno-unused-parameter -Wno-unused-function -Wno-cast-align -Wno-strict-aliasing -Wno-maybe-uninitialized -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fno-common -ffreestanding -fno-builtin -mapcs -gdwarf-3 -std=gnu++11 -ffunction-sections -fdata-sections -fno-rtti -fno-exceptions -fno-unwind-tables -fno-use-cxa-atexit -fno-threadsafe-statics -Wno-old-style-declaration -Wno-discarded-qualifiers -Wp,-w -Wno-write-strings -U__INT32_TYPE__ -D__INT32_TYPE__=int -U__UINT32_TYPE__ -D__UINT32_TYPE__="unsigned int" -Os -g -DWB_UNITTEST_BUILD -Wl,--wrap -Wl,_malloc_r -Wl,--wrap -Wl,_calloc_r -Wl,--wrap -Wl,_free_r -Wl,--wrap -Wl,_realloc_r --specs=nano.specs --specs=nosys.specs -Wl,-Map -Wl,target.map -Wl,--gc-sections -Wl,-static -LG:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/app-build/compiler/../platform/nRF5x/linker/gcc -TG:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/app-build/compiler/../platform/nRF5x/linker/gcc/appflash.ld CMakeFiles/Movesense.dir/AccelerometerSampleService.cpp.obj CMakeFiles/Movesense.dir/App.cpp.obj CMakeFiles/Movesense.dir/generated/sbem-code/sbem_definitions.cpp.obj CMakeFiles/Movesense.dir/generated/app-resources/resources.cpp.obj CMakeFiles/Movesense.dir/app-metadata/metadata.cpp.obj -o Movesense G:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/lib/GCCARM/libmovesense-coreD.a -lm -lstdc++ && cd ."
c:/progra~2/gnutoo~1/92019-~1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: G:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/lib/GCCARM/libmovesense-coreD.a(nrf_log_backend_serial.c.obj): in function `nrf_log_backend_serial_hexdump_handler':
E:\BuildAgent\work\939b802005569609\vendor\nRF5_SDK\components\libraries\log\src/nrf_log_backend_serial.c:446: undefined reference to `__locale_ctype_ptr'
c:/progra~2/gnutoo~1/92019-~1/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: G:/Cardiovelo_sur_NAS/Laboratoires/Labo_TI/Labo_Movesense/movesense-device-lib/MovesenseCoreLib/lib/GCCARM/libmovesense-coreD.a(manufacturingdata.c.obj): in function `store_pcba_string':
E:\BuildAgent\work\939b802005569609\nea\hal\manufacturingdata/manufacturingdata.c:926: undefined reference to `__locale_ctype_ptr'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed
The first error is:
E:\BuildAgent\work\939b802005569609\vendor\nRF5_SDK\components\libraries\log\src/nrf_log_backend_serial.c:446: undefined reference to `__locale_ctype_ptr'
I installed nrfutil (version 6.0.1) on python 2.7.9 (default version on my PC).
Obviously, there is something that does not work and I need help to solve the problem.
OKAY. The problem was 18 "in front of the screen! I had installed the wrong version of the GNU Toolchain for ARM Embedded compiler. However, it was well written to choose the 2017q4 version.
The subject can be considered closed.
I'm new to all this. The GLEW folder is on my Windows drive, and I'm trying to build it with MinGW-w64 from MSYS2 to use in an OpenGL program. The fresh MSYS2 install is fully up to date and is running from /MSYS2/mingw32.exe. The only extra packages installed into MSYS2 are git, mingw-w64-x86_64-gcc and base-devel.
$ make SYSTEM=linux-mingw-w64
i686-w64-mingw32-gcc -DGLEW_NO_GLU -DGLEW_BUILD -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/linux-mingw-w64/default/shared/glew.o -c src/glew.c
i686-w64-mingw32-ld -shared -soname libglew32.dll --out-implib lib/libglew32.dll.a -o lib/glew32.dll tmp/linux-mingw-w64/default/shared/glew.o -nostdlib -lopengl32 -lgdi32 -luser32 -lkernel32
make: i686-w64-mingw32-ld: Command not found
make: *** [Makefile:122: lib/glew32.dll] Error 127
In windows I can look and find i686-w64-mingw32-gcc.exe located in \MSYS2\mingw32\bin\ but i686-w64-mingw32-ld is nowhere to be found within \MSYS2\
If I enter only "make", which I think is using a different SYSTEM= option, I get this:
$ make
gcc -fno-builtin -DGLEW_NO_GLU -DGLEW_BUILD -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/mingw/default/shared/glew.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll tmp/mingw/default/shared/glew.o -L/mingw/lib -nostdlib -lopengl32 -lgdi32 -luser32 -lkernel32
strip -x lib/glew32.dll
sed \
-e "s|#prefix#|/usr|g" \
-e "s|#libdir#|/usr/lib|g" \
-e "s|#exec_prefix#|/usr/bin|g" \
-e "s|#includedir#|/usr/include/GL|g" \
-e "s|#version#|2.1.0|g" \
-e "s|#cflags#||g" \
-e "s|#libname#|glew32|g" \
-e "s|#requireslib#|glu|g" \
< glew.pc.in > glew.pc
gcc -fno-builtin -DGLEW_NO_GLU -DGLEW_STATIC -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/mingw/default/static/glew.o -c src/glew.c
ar rv lib/libglew32.a tmp/mingw/default/static/glew.o
a - tmp/mingw/default/static/glew.o
C:\MSYS2\mingw32\bin\ar.exe: creating lib/libglew32.a
strip -x lib/libglew32.a
gcc -fno-builtin -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/mingw/default/shared/glewinfo.o -c src/glewinfo.c
gcc -fno-builtin -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o bin/glewinfo.exe tmp/mingw/default/shared/glewinfo.o -Llib -lglew32 -L/mingw/lib -nostdlib -lopengl32 -lgdi32 -luser32 -lkernel32
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x33): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x54): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x5c): undefined reference to `strlen'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x90): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0xb8): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0xed): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x109): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x111): undefined reference to `strlen'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x12d): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x152): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x187): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1a4): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1ac): undefined reference to `strlen'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1dc): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e9): undefined reference to `fflush'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e46e): undefined reference to `sscanf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e492): undefined reference to `strcmp'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e4aa): undefined reference to `strcmp'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e4c9): undefined reference to `strcmp'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e500): undefined reference to `strcmp'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e51f): undefined reference to `strcmp'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e544): more undefined references to `strcmp' follow
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e596): undefined reference to `strtol'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e5b5): undefined reference to `strcmp'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e5df): undefined reference to `strcmp'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e620): undefined reference to `memset'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x1e716): undefined reference to `memset'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text+0x142): undefined reference to `fflush'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x1d): undefined reference to `__main'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x98): undefined reference to `fopen'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0xba): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0xcf): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0xe4): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x10b): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x127): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x160): more undefined references to `fprintf' follow
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x177d): undefined reference to `_imp____acrt_iob_func'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x178f): undefined reference to `fclose'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x17af): undefined reference to `_imp____acrt_iob_func'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x17bf): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x17d3): undefined reference to `_imp____acrt_iob_func'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x17e3): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x1808): undefined reference to `_imp____acrt_iob_func'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x181c): undefined reference to `fprintf'
tmp/mingw/default/shared/glewinfo.o:glewinfo.c:(.text.startup+0x1838): undefined reference to `_imp____acrt_iob_func'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:181: bin/glewinfo.exe] Error 1
So over on the GLEW git, it's recommended to fix this error that I modify the Makefile in a certain way, which I did. After that, if I run only "make", my /lib's are built, but my object files in /src are not there:
$ make
gcc -fno-builtin -DGLEW_NO_GLU -DGLEW_BUILD -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/mingw/default/shared/glew.o -c src/glew.c
gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a -o lib/glew32.dll tmp/mingw/default/shared/glew.o -L/mingw/lib -nostdlib -lopengl32 -lgdi32 -luser32 -lkernel32
strip -x lib/glew32.dll
sed \
-e "s|#prefix#|/usr|g" \
-e "s|#libdir#|/usr/lib|g" \
-e "s|#exec_prefix#|/usr/bin|g" \
-e "s|#includedir#|/usr/include/GL|g" \
-e "s|#version#|2.1.0|g" \
-e "s|#cflags#||g" \
-e "s|#libname#|glew32|g" \
-e "s|#requireslib#|glu|g" \
< glew.pc.in > glew.pc
gcc -fno-builtin -DGLEW_NO_GLU -DGLEW_STATIC -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/mingw/default/static/glew.o -c src/glew.c
ar rv lib/libglew32.a tmp/mingw/default/static/glew.o
a - tmp/mingw/default/static/glew.o
C:\MSYS2\mingw32\bin\ar.exe: creating lib/libglew32.a
strip -x lib/libglew32.a
gcc -fno-builtin -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/mingw/default/shared/glewinfo.o -c src/glewinfo.c
gcc -fno-builtin -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o bin/glewinfo.exe tmp/mingw/default/shared/glewinfo.o -Llib -lglew32 -L/mingw/lib -lopengl32 -lgdi32 -luser32 -lkernel32
strip -x bin/glewinfo.exe
gcc -fno-builtin -DGLEW_NO_GLU -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o tmp/mingw/default/shared/visualinfo.o -c src/visualinfo.c
gcc -fno-builtin -O2 -Wall -W -Iinclude -fno-builtin -fno-stack-protector -o bin/visualinfo.exe tmp/mingw/default/shared/visualinfo.o -Llib -lglew32 -L/mingw/lib -lopengl32 -lgdi32 -luser32 -lkernel32
strip -x bin/visualinfo.exe
If I run "make SYSTEM=linux-mingw-w64" after the recommended fix, it gives the same error as it did before and nothing is built. I want to build with this option since I'm going to be compiling my OGL project that calls for GLEW, using MinGW-w64 32-bit.
Questions:
Why is i686-w64-mingw32-lb missing, and how can I obtain it?
Why does "make" without the SYSTEM= flag fail to build the .o files into /src but give no errors?
I'm doing a socket project on win10, and I get these errors.
g++ -ggdb -std=c++11 -Wall -pedantic -o calcserver CalcServer.c
DieWithError.c HandleTCPClient.c CalcFramer.cpp CalcParser.cpp
C:\Users\HARRYS~1\AppData\Local\Temp\cceLC8Xb.o: In function `main':
D:\src/CalcServer.c:35: undefined reference to `__imp_socket'
D:\src/CalcServer.c:41: undefined reference to `__imp_htonl'
D:\src/CalcServer.c:42: undefined reference to `__imp_htons'
D:\src/CalcServer.c:45: undefined reference to `__imp_bind'
D:\src/CalcServer.c:49: undefined reference to `__imp_listen'
D:\src/CalcServer.c:58: undefined reference to `__imp_accept'
D:\src/CalcServer.c:64: undefined reference to `__imp_inet_ntoa'
collect2.exe: error: ld returned 1 exit status
make: *** [calcserver] Error 1
I tried to link Ws2_32.lib. I download Ws2_32.lib under directory src, and modify my makefile like this:
CC=g++
CFLAGS=-ggdb -std=c++11 -Wall -pedantic
LINKFLAGS = -L"D:\src" -lWS2_32
H_FILES=CalcFramer.hpp CalcParser.hpp
FILES=CalcServer.c DieWithError.c HandleTCPClient.c CalcFramer.cpp CalcParser.cpp
all: calcserver
calcserver: $(FILES) $(H_FILES)
$(CC) $(CFLAGS) -o calcserver $(FILES)
clean:
rm -rf calcserver
However, I still get the above errors. I've already changed all the sys/socket.h headers to Winsock.h and Winsock2.h. So I think it's not that part that leads me to the errors.
I'm trying to understand the process of static linking, loading of GCC:
I have the following toy program
#include "stdio.h"
int main() {
fprintf(stdout, "Hello World \n");
return 0 ;
}
I can compile it and run file as follows:
gcc -static -std=gnu99 -Wall -Wno-unused -g test.c -o test;
But as soon as I try to separate out the compile and linking process as follows:
gcc -static -std=gnu99 -Wall -Wno-unused -g test.c -c;
ld -o test -T link.lds test.o
where the link.lds is
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}
I get the error "undefined reference to stdouttest.o: In function `main':
test.c:(.text+0x7): undefined reference to `stdout'
test.c:(.text+0x1e): undefined reference to `fwrite'
If I try adding the flag -lc to ld, it tells me that it is not found. I've tried running gcc with -lc
and/or -static-libgcc but I have the same problem.
What am I doing wrong?
Do
gcc -v -static -std=gnu99 -Wall -Wno-unused -g test.c
and look for the collect2 tag.
In my case it is
collect2 --sysroot=/ --build-id -m elf_x86_64 --hash-style=gnu --as-needed -static -z relro -o test /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbeginT.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. /tmp/ccoR98Xr.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
You have to replace the temporary object file. In my case I replaced /tmp/ccoR98Xr.o with test.o. Then do
gcc -c -std=gnu99 -Wall -Wno-unused -g test.c
ld --sysroot=/ --build-id -m elf_x86_64 --hash-style=gnu --as-needed -static -z relro -o test /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.8/crtbeginT.o -L/usr/lib/gcc/x86_64-linux-gnu/4.8 -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.8/../../.. test.o --start-group -lgcc -lgcc_eh -lc --end-group /usr/lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
It links to the object files : crt1.o, crti.o, crtbeginT.o, crtend.o, and crtn.o.
It links to the libraires: libgcc.a, libgcc_eh.a, and libc.a.
You can replace --start-group -lgcc -lgcc_eh -lc --end-group with -lgcc -lc -lgcc_eh -lc if you like.
Knowing this we can simply this to
ln -s `gcc -print-file-name=crt1.o`
ln -s `gcc -print-file-name=crti.o`
ln -s `gcc -print-file-name=crtn.o`
ln -s `gcc -print-file-name=libgcc_eh.a`
ln -s `gcc -print-file-name=libc.a`
gcc -c -std=gnu99 -Wall -Wno-unused -g test.c
ld -m elf_x86_64 -o test crt1.o crti.o test.o libc.a libgcc_eh.a libc.a crtn.o
I did not use crtbeginT.o, crtend.o, and libgcc.a because it worked without them.
Take a look at this, strace does the job (show you the secrets) but you will soon realize there are tons of options in it... You need to link a few stuff together (from GNU C lib) to get your executable, not only your object... You can add grep 'exec' in the end to make it cleaner.
Uhhh, also you need to do this:
as obj.s -o obj.o
Use GNU assembler to convert your .s to .o then link with ld.
$ rvm install ruby-1.8.7-p249
Installing Ruby from source to: /home/sayuj/.rvm/rubies/ruby-1.8.7-p249, this may take a while depending on your cpu(s)...
ruby-1.8.7-p249 - #fetching
ruby-1.8.7-p249 - #extracted to /home/sayuj/.rvm/src/ruby-1.8.7-p249 (already extracted)
ruby-1.8.7-p249 - #configuring
ruby-1.8.7-p249 - #compiling
ERROR: Error running 'make ', please read /home/sayuj/.rvm/log/ruby-1.8.7-p249/make.log
ERROR: There has been an error while running make. Halting the installation.
EDIT
I use Ubuntu 11.10
$ cat /home/sayuj/.rvm/log/ruby-1.8.7-p249/make.log
[2011-10-17 15:34:49] make
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -L. -rdynamic -Wl,-export-dynamic main.o libruby-static.a -lrt -ldl -lcrypt -lm -o miniruby
rbconfig.rb updated
gcc -shared -Wl,-soname,libruby.so.1.8 array.o bignum.o class.o compar.o dir.o dln.o enum.o enumerator.o error.o eval.o file.o gc.o hash.o inits.o io.o marshal.o math.o numeric.o object.o pack.o parse.o process.o prec.o random.o range.o re.o regex.o ruby.o signal.o sprintf.o st.o string.o struct.o time.o util.o variable.o version.o dmyext.o -lrt -ldl -lcrypt -lm -o libruby.so.1.8.7
compiling Win32API
compiling bigdecimal
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/bigdecimal'
gcc -shared -o ../../.ext/x86_64-linux/bigdecimal.so bigdecimal.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/bigdecimal'
compiling curses
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/curses'
gcc -shared -o ../../.ext/x86_64-linux/curses.so curses.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lncurses -ltinfo -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/curses'
compiling dbm
compiling digest
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest'
gcc -shared -o ../../.ext/x86_64-linux/digest.so digest.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
cp ../.././ext/digest/digest.h ../../.ext/x86_64-linux
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest'
compiling digest/bubblebabble
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/bubblebabble'
gcc -shared -o ../../../.ext/x86_64-linux/digest/bubblebabble.so bubblebabble.o -L. -L../../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/bubblebabble'
compiling digest/md5
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/md5'
gcc -shared -o ../../../.ext/x86_64-linux/digest/md5.so md5init.o md5ossl.o -L. -L../../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lcrypto -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/md5'
compiling digest/rmd160
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/rmd160'
gcc -shared -o ../../../.ext/x86_64-linux/digest/rmd160.so rmd160init.o rmd160ossl.o -L. -L../../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lcrypto -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/rmd160'
compiling digest/sha1
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/sha1'
gcc -shared -o ../../../.ext/x86_64-linux/digest/sha1.so sha1init.o sha1ossl.o -L. -L../../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lcrypto -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/sha1'
compiling digest/sha2
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/sha2'
gcc -shared -o ../../../.ext/x86_64-linux/digest/sha2.so sha2.o sha2init.o -L. -L../../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/digest/sha2'
compiling dl
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/dl'
gcc -shared -o ../../.ext/x86_64-linux/dl.so handle.o ptr.o dl.o sym.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -ldl -lrt -ldl -lcrypt -lm -lc
cp dlconfig.h ../../.ext/x86_64-linux
cp ../.././ext/dl/dl.h ../../.ext/x86_64-linux
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/dl'
compiling etc
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/etc'
gcc -shared -o ../../.ext/x86_64-linux/etc.so etc.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/etc'
compiling fcntl
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/fcntl'
gcc -shared -o ../../.ext/x86_64-linux/fcntl.so fcntl.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/fcntl'
compiling gdbm
compiling iconv
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/iconv'
gcc -shared -o ../../.ext/x86_64-linux/iconv.so iconv.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/iconv'
compiling io/wait
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/io/wait'
gcc -shared -o ../../../.ext/x86_64-linux/io/wait.so wait.o -L. -L../../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/io/wait'
compiling nkf
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/nkf'
gcc -shared -o ../../.ext/x86_64-linux/nkf.so nkf.o -L. -L../.. -L. -rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -L/home/sayuj/.rvm/rubies/ruby-1.8.7-p249/lib -lruby -lrt -ldl -lcrypt -lm -lc
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/nkf'
compiling openssl
make[1]: Entering directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/openssl'
gcc -I. -I../.. -I../../. -I../.././ext/openssl -DRUBY_EXTCONF_H=\"extconf.h\" -fPIC -g -O2 -fPIC -c ossl_pkcs7.c
ossl_pkcs7.c: In function ‘ossl_pkcs7si_new’:
ossl_pkcs7.c:89:5: warning: passing argument 2 of ‘ASN1_dup’ from incompatible pointer type [enabled by default]
/usr/include/openssl/asn1.h:955:7: note: expected ‘void * (*)(void **, const unsigned char **, long int)’ but argument is of type ‘char * (*)()’
ossl_pkcs7.c: In function ‘DupPKCS7SignerPtr’:
ossl_pkcs7.c:102:5: warning: passing argument 2 of ‘ASN1_dup’ from incompatible pointer type [enabled by default]
/usr/include/openssl/asn1.h:955:7: note: expected ‘void * (*)(void **, const unsigned char **, long int)’ but argument is of type ‘char * (*)()’
ossl_pkcs7.c: In function ‘ossl_pkcs7ri_new’:
ossl_pkcs7.c:115:5: warning: passing argument 2 of ‘ASN1_dup’ from incompatible pointer type [enabled by default]
/usr/include/openssl/asn1.h:955:7: note: expected ‘void * (*)(void **, const unsigned char **, long int)’ but argument is of type ‘char * (*)()’
ossl_pkcs7.c: In function ‘DupPKCS7RecipientPtr’:
ossl_pkcs7.c:128:5: warning: passing argument 2 of ‘ASN1_dup’ from incompatible pointer type [enabled by default]
/usr/include/openssl/asn1.h:955:7: note: expected ‘void * (*)(void **, const unsigned char **, long int)’ but argument is of type ‘char * (*)()’
ossl_pkcs7.c: At top level:
ossl_pkcs7.c:573:1: error: unknown type name ‘STACK’
ossl_pkcs7.c: In function ‘pkcs7_get_certs_or_crls’:
ossl_pkcs7.c:593:15: warning: assignment from incompatible pointer type [enabled by default]
ossl_pkcs7.c:596:31: warning: pointer type mismatch in conditional expression [enabled by default]
ossl_pkcs7.c: In function ‘ossl_pkcs7_set_certificates’:
ossl_pkcs7.c:611:11: warning: assignment from incompatible pointer type [enabled by default]
ossl_pkcs7.c: In function ‘ossl_pkcs7_get_certificates’:
ossl_pkcs7.c:621:5: warning: passing argument 1 of ‘ossl_x509_sk2ary’ from incompatible pointer type [enabled by default]
ossl.h:121:7: note: expected ‘struct stack_st_X509 *’ but argument is of type ‘int *’
ossl_pkcs7.c: In function ‘ossl_pkcs7_set_crls’:
ossl_pkcs7.c:651:10: warning: assignment from incompatible pointer type [enabled by default]
ossl_pkcs7.c: In function ‘ossl_pkcs7_get_crls’:
ossl_pkcs7.c:661:5: warning: passing argument 1 of ‘ossl_x509crl_sk2ary’ from incompatible pointer type [enabled by default]
ossl.h:122:7: note: expected ‘struct stack_st_X509_CRL *’ but argument is of type ‘int *’
make[1]: *** [ossl_pkcs7.o] Error 1
make[1]: Leaving directory `/home/sayuj/.rvm/src/ruby-1.8.7-p249/ext/openssl'
make: *** [all] Error 1
How can I fix this?
From here : http://ahmy.yulrizka.com/2011/10/ruby-ree-1-8-7-openssl-error/
rvm pkg install openssl
And from one of the answers here: https://stackoverflow.com/a/8544958/178975
rvm install ruby-1.8.7 --with-openssl-dir=<rvm_dir>/usr
where rvm_dir could be $HOME/.rvm or /usr/local/rvm or wherever you have installed rvm
Looks like the problem is:
ossl_pkcs7.c:573:1: error: unknown type name ‘STACK’
My guess is its a dependancy issue.
Look at the output of:
rvm notes
And ensure you have followed all the steps for Ubuntu.
One obvious thing is that Ubuntu 11.10 is only just out - might be worth searching/posting on the Ubuntu forums to see if anyone there has had any issues with it and rvm.
Be sure to install ruby with rvm and giving the open-ssl-dir explicitly like this:
rvm cleanup
rvm install ruby-1.8.7 --with-openssl-dir=$HOME/.rvm/usr