Reputation: 3720
This is the first time I've used Eclipse for writing C code, so the answer might be very simple. I'm also figuring that Eclipse is already setup to compile, build, and link appropriately. This is being ran on a Windows 7 64-bit machine.
In my C code, it seems that anytime I use the malloc()
or even printf()
function it puts the red squiggly line below it. Just the function is underlined, not the casting or even the parameters.
Here is what the line of code:
#include <stdlib.h>
#include <stdio.h>
int* list; //This is a global variable
int main(){
//...inside a function
list = (int*) malloc( sizeof(int) ); // Out of this line, only the word "malloc" is underlined in red.
printf(""); //printf also gives me an error
return 0;
}
When I hover my mouse over the error, it says the following:
Function 'malloc' could not be resolved.
Am I even using malloc()
right?
Upvotes: 1
Views: 3735
Reputation: 26652
According to the clang and the cc compilers, your code is ok and it compiles in Eclipse Juno:
Building target: code
Invoking: GCC C Linker
gcc -o "code" ./code.o
Finished building target: code
I think you can look at this question
"Unresolved inclusion" error with Eclipse CDT for C standard library headers
if you want a complete solution.
Upvotes: 1
Reputation: 8195
You haven't provided enough information. You need to provide a complete program including malloc
, however small, that doesn't compile. You also need to give the compiler error you get, and whether the problem is just with malloc
or all standard library functions.
At a guess, your compiler software isn't installed correctly and it can't find stdlib.h
.
As you've now added that no standard library functions work, there's definitely a problem with your compiler set up (this is nothing to do with malloc
).
Upvotes: 2