Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7952 Discussions

extern "C" not working with Linux icpc but works find with Mac

Noel_B_
Novice
1,718 Views

Attached is simple reproducer that works on Mac with:

 

s1038899:~ kbelco$ icpc --version

icpc (ICC) 19.1.3 20200925

Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.

 

but fails on Linux with Intel 19.1.4

 

The name mangling is different, you get the leading underscore on the Mac which is correct but on Linux you don't get the leading underscore.

 

I have to inline the source code since the attachment is rejected.

 

#include "junk.hpp"

 

int foo(char*) {

  return 0;

}

void foo2(char*) {

}

int main(int, char**) {

  return 0;

}

 

Here's the Mac output:

s1038899:~ kbelco$ nm a.out | grep -i foo

0000000100000c10 T _foo

0000000100000c20 T _foo2

 

Here's the Linux output:

 

-bash-4.2$ nm a.out | grep -i foo

0000000000400c40 T foo

0000000000400c50 T foo2

0 Kudos
1 Solution
Gopika_Intel
Moderator
1,653 Views

Hi,

 

Thank you for reaching out. We’ll check it and get back to you.

 

Regards

Gopika Ajit


View solution in original post

0 Kudos
4 Replies
Gopika_Intel
Moderator
1,654 Views

Hi,

 

Thank you for reaching out. We’ll check it and get back to you.

 

Regards

Gopika Ajit


0 Kudos
Viet_H_Intel
Moderator
1,647 Views

On Linux, it needs to be compatible with Gnu. If icpc generated _foo symbol, then there would be an "undefined reference to foo" when you try to link mix objects (compile with icpc/g++).


Thanks,


0 Kudos
Viet_H_Intel
Moderator
1,564 Views

Please let us know if you have any other questions. Otherwise, we would like to close this topic.

Thanks,


0 Kudos
Viet_H_Intel
Moderator
1,506 Views

Let's close this ticketIf you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.

Thanks,


0 Kudos
Reply