这是我的Makefile:
CC = gcc
SRC = $(wildcard src/*.c) \
$(wildcard src/utils/*.c)
obj = $(SRC:.c=.o)
LDFLAGS =
output: $(obj)
$(CC) $^ -o $@ $(LDFLAGS)
$(obj): $(SRC)
$(CC) $^ -o $@ $(LDFLAGS)
.PHONY: clean
clean:
rm -f $(obj) main
这是main.c:
#include<stdio.h>
#include "utils/activations.h"
double check();
int main(){
check();
}
double check(){
double output = act(0.2, "sigmoid");
return output;
}
这是激活。c:
#include<stdio.h>
#include<string.h>
#include<math.h>
double act();
double relu();
double sigmoid();
double tan_h();
double act(double x, char actFunc[]){
double y;
if(actFunc == "relu"){
y = relu(x);
}
if(actFunc == "sigmoid"){
y = sigmoid(x);
}
if(actFunc == "tanh"){
y = tan_h(x);
}
return y;
}
double relu(double input){
double output;
if(input < 0){
output = 0;
} else{
output = input;
}
return output;
}
double sigmoid(double input){
return 1/(1+exp(-1*input));
}
double tan_h(double input){
return tanh(input);
}
好吧,这是错误的:
gcc src/main.c src/utils/activations.c -o src/utils/activations.o
gcc src/main.o src/utils/activations.o -o output
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/main.o: in function `mainCRTStartup':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: multiple definition of `mainCRTStartup'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../crt0.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/main.o: in function `mainCRTStartup':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: multiple definition of `WinMainCRTStartup'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../crt0.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/main.o:cygming-crtbegin.c:(.text+0x90): multiple definition of `__gcc_register_frame'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/main.o:cygming-crtbegin.c:(.text+0x150): multiple definition of `__gcc_deregister_frame'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/crtbegin.o:cygming-crtbegin.c:(.text+0xc0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/main.o:cygming-crtbegin.c:(.data+0x4): multiple definition of `__dso_handle'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/crtbegin.o:cygming-crtbegin.c:(.data+0x4): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `mainCRTStartup':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: multiple definition of `mainCRTStartup'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../crt0.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `mainCRTStartup':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: multiple definition of `WinMainCRTStartup'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../crt0.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/crt0.c:21: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtbegin.c:(.text+0x90): multiple definition of `__gcc_register_frame'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtbegin.c:(.text+0x150): multiple definition of `__gcc_deregister_frame'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/crtbegin.o:cygming-crtbegin.c:(.text+0xc0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:main.c:(.text+0x180): multiple definition of `main'; src/main.o:main.c:(.text+0x180): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:main.c:(.text+0x199): multiple definition of `check'; src/main.o:main.c:(.text+0x199): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.text+0x1c0): multiple definition of `act'; src/main.o:activations.c:(.text+0x1c0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.text+0x21c): multiple definition of `relu'; src/main.o:activations.c:(.text+0x21c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.text+0x24b): multiple definition of `sigmoid'; src/main.o:activations.c:(.text+0x24b): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.text+0x274): multiple definition of `tan_h'; src/main.o:activations.c:(.text+0x274): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_crt0':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/cygwin_crt0.c:18: multiple definition of `cygwin_crt0'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/cygwin_crt0.c:18: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_premain0':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain0.c:13: multiple definition of `cygwin_premain0'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain0.c:13: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_premain1':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain1.c:13: multiple definition of `cygwin_premain1'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain1.c:13: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_premain2':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain2.c:13: multiple definition of `cygwin_premain2'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain2.c:13: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_premain3':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain3.c:13: multiple definition of `cygwin_premain3'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/premain3.c:13: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_crt0_common@8':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/_cygwin_crt0_common.cc:91: multiple definition of `_cygwin_crt0_common@8'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/_cygwin_crt0_common.cc:91: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_dll_entry@12':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/dll_entry.c:15: multiple definition of `_cygwin_dll_entry@12'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/dll_entry.c:15: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_noncygwin_dll_entry@12':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/dll_entry.c:15: multiple definition of `_cygwin_noncygwin_dll_entry@12'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/dll_entry.c:15: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `DllMain@12':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/dll_main.cc:35: multiple definition of `DllMain@12'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/dll_main.cc:35: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `pei386_runtime_relocator':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/pseudo-reloc-dummy.c:10: multiple definition of `_pei386_runtime_relocator'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/pseudo-reloc-dummy.c:10: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o: in function `cygwin_attach_dll':
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/cygwin_attach_dll.c:19: multiple definition of `cygwin_attach_dll'; src/main.o:/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/cygwin_attach_dll.c:19: first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.rdata+0x304): multiple definition of `__RUNTIME_PSEUDO_RELOC_LIST__'; src/main.o:activations.c:(.rdata+0x304): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtbegin.c:(.data+0x0): multiple definition of `_data_start__'; src/main.o:cygming-crtbegin.c:(.data+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtend.c:(.text+0x82c): multiple definition of `__DTOR_LIST__'; src/main.o:cygming-crtend.c:(.text+0x82c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x294): multiple definition of `__cxa_atexit'; src/main.o:fake:(.text+0x294): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x798): multiple definition of `free'; src/main.o:fake:(.text+0x798): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x108): multiple definition of `_nm___impure_ptr'; src/main.o:crt0.c:(.idata+0x108): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xc0): multiple definition of `_imp__tanh'; src/main.o:crt0.c:(.idata+0xc0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__tls_start__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.rdata+0x304): multiple definition of `_rt_psrelocs_start'; src/main.o:activations.c:(.rdata+0x304): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xa0): multiple definition of `_imp__cygwin_detach_dll'; src/main.o:crt0.c:(.idata+0xa0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xl_start__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xi_start__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xi_end__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.bss+0x20): multiple definition of `__dynamically_loaded'; src/main.o:activations.c:(.bss+0x20): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x800): multiple definition of `dll_dllcrt0'; src/main.o:fake:(.text+0x800): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x808): multiple definition of `GetModuleHandleA@4'; src/main.o:fake:(.text+0x808): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.bss+0x100): multiple definition of `hmod_libgcc'; src/main.o:activations.c:(.bss+0x100): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtbegin.c:(.bss+0x0): multiple definition of `_bss_start__'; src/main.o:cygming-crtbegin.c:(.bss+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.rdata+0x304): multiple definition of `__RUNTIME_PSEUDO_RELOC_LIST_END__'; src/main.o:activations.c:(.rdata+0x304): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.bss+0x1c): multiple definition of `environ'; src/main.o:activations.c:(.bss+0x1c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xac): multiple definition of `_imp__exp'; src/main.o:crt0.c:(.idata+0xac): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xd0): multiple definition of `_imp__GetProcAddress@8'; src/main.o:crt0.c:(.idata+0xd0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xp_start__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xp_end__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xb8): multiple definition of `_imp__posix_memalign'; src/main.o:crt0.c:(.idata+0xb8): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xc8): multiple definition of `_imp__FreeLibrary@4'; src/main.o:crt0.c:(.idata+0xc8): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x98): multiple definition of `_imp___impure_ptr'; src/main.o:crt0.c:(.idata+0x98): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xdc): multiple definition of `_IAT_end__'; src/main.o:crt0.c:(.idata+0xdc): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x790): multiple definition of `cygwin_internal'; src/main.o:fake:(.text+0x790): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.rdata+0x304): multiple definition of `_RUNTIME_PSEUDO_RELOC_LIST__'; src/main.o:activations.c:(.rdata+0x304): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.data+0x40): multiple definition of `_data_end__'; src/main.o:activations.c:(.data+0x40): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtend.c:(.text+0x820): multiple definition of `_CTOR_LIST__'; src/main.o:cygming-crtend.c:(.text+0x820): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.bss+0x104): multiple definition of `_bss_end__'; src/main.o:activations.c:(.bss+0x104): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xc_end__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x29c): multiple definition of `__main'; src/main.o:fake:(.text+0x29c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xc_start__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x7a8): multiple definition of `posix_memalign'; src/main.o:fake:(.text+0x7a8): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x238): multiple definition of `_lib32_libkernel32_a_iname'; src/main.o:crt0.c:(.idata+0x238): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtend.c:(.text+0x820): multiple definition of `__CTOR_LIST__'; src/main.o:cygming-crtend.c:(.text+0x820): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x780): multiple definition of `calloc'; src/main.o:fake:(.text+0x780): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.bss+0x18): multiple definition of `_fmode'; src/main.o:activations.c:(.bss+0x18): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x21c): multiple definition of `cygwin1_dll_iname'; src/main.o:crt0.c:(.idata+0x21c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x0): multiple definition of `_head_cygwin1_dll'; src/main.o:crt0.c:(.idata+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x90): multiple definition of `_imp____main'; src/main.o:crt0.c:(.idata+0x90): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x7b0): multiple definition of `realloc'; src/main.o:fake:(.text+0x7b0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xb4): multiple definition of `_imp__malloc'; src/main.o:crt0.c:(.idata+0xb4): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x788): multiple definition of `cygwin_detach_dll'; src/main.o:fake:(.text+0x788): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xa8): multiple definition of `_imp__dll_dllcrt0'; src/main.o:crt0.c:(.idata+0xa8): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x2a4): multiple definition of `exp'; src/main.o:fake:(.text+0x2a4): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xbc): multiple definition of `_imp__realloc'; src/main.o:crt0.c:(.idata+0xbc): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x8c): multiple definition of `_IAT_start__'; src/main.o:crt0.c:(.idata+0x8c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x94): multiple definition of `_imp___dll_crt0@0'; src/main.o:crt0.c:(.idata+0x94): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `_end__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xcc): multiple definition of `_imp__GetModuleHandleA@4'; src/main.o:crt0.c:(.idata+0xcc): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x7a0): multiple definition of `malloc'; src/main.o:fake:(.text+0x7a0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtend.c:(.text+0x82c): multiple definition of `_DTOR_LIST__'; src/main.o:cygming-crtend.c:(.text+0x82c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x8c): multiple definition of `_imp____cxa_atexit'; src/main.o:crt0.c:(.idata+0x8c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xt_start__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x9c): multiple definition of `_imp__calloc'; src/main.o:crt0.c:(.idata+0x9c): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xa4): multiple definition of `_imp__cygwin_internal'; src/main.o:crt0.c:(.idata+0xa4): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__tls_end__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.data+0x20): multiple definition of `__cygwin_cxx_malloc'; src/main.o:activations.c:(.data+0x20): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:fake:(.text+0x2ac): multiple definition of `tanh'; src/main.o:fake:(.text+0x2ac): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xb0): multiple definition of `_imp__free'; src/main.o:crt0.c:(.idata+0xb0): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:cygming-crtbegin.c:(.data+0x4): multiple definition of `__dso_handle'; /usr/lib/gcc/i686-pc-cygwin/9.3.0/crtbegin.o:cygming-crtbegin.c:(.data+0x4): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0x14): multiple definition of `_head_lib32_libkernel32_a'; src/main.o:crt0.c:(.idata+0x14): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.rdata+0x304): multiple definition of `_rt_psrelocs_end'; src/main.o:activations.c:(.rdata+0x304): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.idata+0xd4): multiple definition of `_imp__LoadLibraryA@4'; src/main.o:crt0.c:(.idata+0xd4): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:activations.c:(.rdata+0x304): multiple definition of `_RUNTIME_PSEUDO_RELOC_LIST_END__'; src/main.o:activations.c:(.rdata+0x304): first defined here
/usr/lib/gcc/i686-pc-cygwin/9.3.0/../../../../i686-pc-cygwin/bin/ld: src/utils/activations.o:crt0.c:(.rsrc+0x0): multiple definition of `__crt_xt_end__'; src/main.o:crt0.c:(.rsrc+0x0): first defined here
make: *** [Makefile:9: output] Error 1
我是Makefile的新手,有点熟悉C
您忘记/省略了编译目标文件。第一步,您将获得可执行文件。因此,您不需要规则$(obj): $(SRC)
。
CC = gcc
SRC = $(wildcard src/*.c) \
$(wildcard src/utils/*.c)
obj = $(SRC:.c=.o)
LDFLAGS =
output: $(SRC)
$(CC) $^ -o $@ $(LDFLAGS)
.PHONY: clean
clean:
rm -f $(obj) output
如果要编译目标文件,请参见下面
CC = gcc
SRC = $(wildcard src/*.c) $(wildcard src/utils/*.c)
obj = $(SRC:.c=.o)
LDFLAGS =
output: $(obj)
$(CC) $^ -o $@ $(LDFLAGS)
%.o: %.c $(SRC)
$(CC) -c -o $@ $< $(CFLAGS)
.PHONY: clean
clean:
rm -f $(obj) main
链接程序告诉您,您对X的定义比应有的多,并且应该只有一个。在这种情况下,您必须跟踪可能在何处定义了这些其他定义。在这个简单的项目中,这很容易,请查看用于编译和链接的命令:
output: $(obj)
$(CC) $^ -o $@ $(LDFLAGS)
$(obj): $(SRC)
$(CC) $^ -o $@ $(LDFLAGS)
在gcc中,您可以通过两种方式:
您已在同一步骤中两次编译和链接。第一个目标($(obj): $(SRC)
)编译并链接了您的可执行文件,然后您的第二个目标试图链接已链接的内容。
您现在可以删除不必要的链接目标,或在编译目标中告诉gcc
-c
标志)。CC = gcc SRC = $(wildcard src/*.c) $(wildcard src/utils/*.c) obj = $(SRC:.c=.o) LDFLAGS = output: $(obj) $(CC) $^ -o $@ $(LDFLAGS) $(obj): $(SRC) $(CC) -c $^ .PHONY: clean clean: rm -f $(obj) main
立即编译并链接
CC = gcc SRC = $(wildcard src/*.c) $(wildcard src/utils/*.c) obj = $(SRC:.c=.o) LDFLAGS = output: $(SRC) $(CC) $^ -o $@ $(LDFLAGS) .PHONY: clean clean: rm -f $(obj) main