Jump to content

Incomprehensible error... any ideas?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
inline void foo(){}

int main(){foo();}

That seemingly innocent code gives the following linker error:
$gcc -std=c99 -Wall -Wextra -pedantic inlinetest.c

/tmp/cc4A48Yu.o: In function `main':

inlinetest.c:(.text+0x12): undefined reference to `foo'

collect2: ld returned 1 exit status

Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#2
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
Edit:
I didn't check that you were coding in C. I never tried to inline a function in C, so i don't know why that happens.

#3
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
Dunno.

Quote

D:\projects\misc\c>gcc -std=c99 -Wall -Wextra -pedantic main.c

D:\projects\misc\c>gcc --version
gcc (GCC) 3.4.5 (mingw-vista special)
Clean out the project directory, etc.?

#4
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
I don't think inline functions are part of C. As far as I remember were supposed to replace (at least partially) macro's and were something new of C++ that did not appear in C.
Plus , you don't return an integer in main.

#5
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
So, after all it was like i was saying at my first post? it acts like C++. Inline functions are like macros, they expand then called, so you can't produce object code from them.

#6
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts

bobdark said:

I don't think inline functions are part of C. As far as I remember were supposed to replace (at least partially) macro's and were something new of C++ that did not appear in C.
Plus , you don't return an integer in main.

No, inline functions are part of C99, and some compilers supported it as an extension before C99.