Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646
7596 Discussions

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

Noel_B_
Beginner
720 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
655 Views

Hi,

 

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

 

Regards

Gopika Ajit


View solution in original post

4 Replies
Gopika_Intel
Moderator
656 Views

Hi,

 

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

 

Regards

Gopika Ajit


View solution in original post

Viet_H_Intel
Moderator
649 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,


Viet_H_Intel
Moderator
566 Views

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

Thanks,


Viet_H_Intel
Moderator
508 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,


Reply