C/C++: Undefined reference to `main'
Posted: Fri Jun 01, 2007 1:18 pm
έχω το εξής πρόβλημα με τον παρακάτω κώδικα. χρησιμοποιώ Eclipse, και όταν πάω να παράγω τα binaries, μου εμφανίζει το πρόβλημα
Τώρα το πρόβλημα το έχω με την C. Παλιότερα το είχα και με την C++. Είναι κλασσικό prob απ' ότι έχω καταλάβει, αλλά δεν έχω καταφέρει να το λύσω ακόμη
Υπ' όψιν, χρησιμοποιώ managed make c project.
Ορίστε και το autogenerated makefile
ο κώδικας είναι, όπως τον κατέβασα απ' το eclass των λειτουργικών**** Build of configuration Debug for project ops ****
make -k all
Building file: ../ops.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"ops.d" -MT"ops.d" -o"ops.o" "../ops.c"
Finished building: ../ops.c
Building target: ops
Invoking: GCC C Linker
gcc -o"ops" ./ops.o
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [ops] Error 1
make: Target `all' not remade because of errors.
Build complete for project ops
Code: Select all
#include <stdio.h>
int main(){
int child, b;
char command[25]={"find / -name "*.c" -print"};
child=fork();
if (child == 0) //child {
printf("child\n");
execlp (command,(char *) 0);
}
else{ //parent
wait(&b);
printf("parent\n");
}
}
Υπ' όψιν, χρησιμοποιώ managed make c project.
Ορίστε και το autogenerated makefile
Code: Select all
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: ops
# Tool invocations
ops: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C Linker'
g++ -o"ops" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(OBJS)$(C_DEPS)$(EXECUTABLES) ops
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets