I'm trying to create a VxWorks7 Image Project (VIP) that includes my application which overloads new and delete. When I build the VIP and application separately with the app as a Downloadable Kernel Module (DKM) it builds and runs fine by booting the VIP on the target and downloading the App DKM separately with Workbench4. However if I try to build the VIP and the DKM together as a single bootable VIP I get multiple define errors for the new and delete operators from Workbench during the build as follows:
C:/BW/Vehicle/builds/cx20X0Up32BitDebugVsb/krnl/gnu_standard\libgnucplus.a(_x_gnu_delaop.o): In function `operator delete[](void*)':
(.text+0x0): multiple definition of `operator delete[](void*)'
C:/BW/Vehicle/builds/Vehicle/cx20X0Up32BitDebugVsb_SANDYBRIDGEgnu/Vehicle_partialImage/Debug/Vehicle_partialImage.o:C:/BW/Alcatraz/Vehicle/src/IRL/Util/heap.cpp:886: first defined here
C:/BW/Vehicle/builds/cx20X0Up32BitDebugVsb/krnl/gnu_standard\libgnucplus.a(_x_gnu_delop.o): In function `operator delete(void*)':
(.text+0x0): multiple definition of `operator delete(void*)'
C:/BW/Vehicle/builds/Vehicle/cx20X0Up32BitDebugVsb_SANDYBRIDGEgnu/Vehicle_partialImage/Debug/Vehicle_partialImage.o:C:/BW/Alcatraz/Vehicle/src/IRL/Util/heap.cpp:841: first defined here
C:/BW/Vehicle/builds/cx20X0Up32BitDebugVsb/krnl/gnu_standard\libgnucplus.a(_x_gnu_newaop.o): In function `operator new[](unsigned int)':
(.text+0x0): multiple definition of `operator new[](unsigned int)'
C:/BW/Vehicle/builds/Vehicle/cx20X0Up32BitDebugVsb_SANDYBRIDGEgnu/Vehicle_partialImage/Debug/Vehicle_partialImage.o:C:/BW/Alcatraz/Vehicle/src/IRL/Util/heap.cpp:813: first defined here
C:/BW/Vehicle/builds/cx20X0Up32BitDebugVsb/krnl/gnu_standard\libgnucplus.a(_x_gnu_newop.o): In function `operator new(unsigned int)':
(.text+0x0): multiple definition of `operator new(unsigned int)'
C:/BW/Alcatraz/Vehicle/builds/Vehicle/cx20X0Up32BitDebugVsb_SANDYBRIDGEgnu/Vehicle_partialImage/Debug/Vehicle_partialImage.o:C:/BW/Alcatraz/Vehicle/src/IRL/Util/heap.cpp:808: first defined here
collect2.exe: error: ld returned 1 exit status
WindRiver support offered the solution to make the following declarations in the source file where the new and delete operators are overloaded. This is supposed to signal the compiler/linker to omit the library version of new/del operators.
int ___x_gnu_newaop_o = 1;
int ___x_gnu_newop_o = 1;
int ___x_gnu_delaop_o = 1 ;
int ___x_gnu_delop_o = 1;
Doing this I still get the same multiply defined errors as above and WindRiver support hasn't had any viable suggestions. Has anyone had experience trying to overload global ::new and ::delete in VxWorks7 using Gnu compiler?
Here is link to the issue on WindRiver Support 66370. Not sure if it has public access.
Turns out the multiple define after trying the Wind River proposed workaround was due to libraries with circular references and also from using the workaround specifying all overloads when only some were used. I am now able to build without issues using the following and without resorting to a modified standard library which is what we used previously with VxWorks 6.x:
// ======== SPECIAL CASE NEW/DELETE OPERATOR OVERLOAD FOR GNU ========
// The following ___x_gnu_????.o global variable definitions are special
// case indicators to Gnu compiler when building the application into an
// integrated VIP (VxWorks Image Project). They indicate which new and
// delete operators are being overloaded. Doing this avoids a multiple
// definition build error for new/delete operators. This multiple
// definition error is only an issue when building application as an
// integrated VIP and not when app is downloaded separate from VIP as a
// Downloadable Kernel Module (DKM). It is important to only include
// ___x_gnu_????_o variables for the specific operators being
// overloaded. Defining a ___x_gnu_????_o variable for an operator that
// is not actually overloaded will cause a multiple define error also.
// This solution to overloading new/delete was obtained directly from
// Wind River support and is described in case #66370 and as of this
// date is not described anywhere in Wind River documentation.
// link to case #66370 below. -- 2017Jan18jdn
//
// https://windriver.force.com/support/apex/CaseReadOnly?id=5001600000xKkTYAA0
int ___x_gnu_newaop_o = 1; // Indicates overload of new [] operator
int ___x_gnu_newop_o = 1; // Indicates overload of new operator
int ___x_gnu_delaop_o = 1 ; // Indicates overload of delete [] operator
int ___x_gnu_delop_o = 1; // Indicates overload of delete operator