C++ Typesafe Linking

main.c

 

extern void func();

int main(int argc, const char *argv[]) {
  func(); 
  return 0;
}

 

lib.c

 #include <stdio.h>

void func(int i) {
  printf("param: %d\n", i);
}

 

$ gcc main.c lib.c 

$ ./a.out 

param: 134513712

$ g++ main.c lib.c 

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

main.c:(.text+0x7): undefined reference to `func()'

collect2: ld returned 1 exit status

 


你可能感兴趣的:(C++,c,gcc,C#)