- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have a simple shared library that defines a constructor and a destructor using __attribute__((constructor)) and __attribute__((destructor)). Everything is in C. This works fine unless I add -no-cxxlib to the linker command. When I do that then the shared library constructor/destructor are no longer invoked.
Is that intended behavior? Is there a way I can keep them working although I have -no-cxxlib on the command line?
My shared library source code is
#include <stdio.h>
__attribute__((constructor)) void ctor(void) {
printf("Here is the constructor\n");
}
__attribute__((destructor)) void dtor(void) {
printf("Here is the destructor\n");
}
void function(void) {
printf("Here is the function\n");
}
and my application source code is
void function(void);
int main(void) {
function();
return 0;
}
I use this makefile:
ICC = icc
NO_CXXLIB = -no-cxxlib
all: main libsolib.so
LD_LIBRARY_PATH=. ./main
main.o: main.c
$(ICC) -O3 -c -o $@ $<
main: main.o libsolib.so
$(ICC) -o $@ main.c -L. -lsolib
solib.o: solib.c
$(ICC) -W -Wall -fPIC -c -o $@ $<
libsolib.so: solib.o
$(ICC) -o $@ -O3 -shared -static-intel $(NO_CXXLIB) $<
clean:
rm -f *.so *.o
Running "make all" (unexpectedly) prints
Here is the function
while running "make NO_CXXLIB= all" prints (constructor and destructor are invoked)
Here is the constructor
Here is the function
Here is the destructor
It seems that -no-cxxlib not only prevents linking of gcc C++ code but also library startup code?
I am on Linux and this the compiler version I am using:
icc (ICC) 18.0.5 20180823
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We tried running it on icc (ICC) 2021.2.0 version, both the constructor and the destructor got invoked for both the cases(fig. attached below).
Please try upgrading to latest version icc by installing latest oneAPI Toolkit.
Link:https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html
Regards
Rajesh.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We tried running it on icc (ICC) 2021.2.0 version, both the constructor and the destructor got invoked for both the cases(fig. attached below).
Please try upgrading to latest version icc by installing latest oneAPI Toolkit.
Link:https://software.intel.com/content/www/us/en/develop/tools/oneapi/base-toolkit/download.html
Regards
Rajesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for checking. Unfortunately, upgrading my Intel compiler is not an option for me.
Given what you say, I conclude that this is unexpected behavior and probably a bug in my current version. I will try to work around this then.
Regards
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We do not support ICC 18.0 anymore. So, can we proceed to close this thread?
Regards
Rajesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, sure. Sorry for not doing that before. I accepted your initial answer now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the confirmation!
As this issue has been resolved, we will no longer respond to this thread. If you require any additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.
Have a Good day.
Regards
Rajesh.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page