Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I encountered a bunch of <code>LNK4006</code> errors when linking my app to a library (call it library LIB_Y) that made heavy use of <code>std::vector&lt;std::string&gt;</code>, which I also did in my app. After a bit of experimenting I found one solution that worked -- wrap LIB_Y in a separate DLL that calls LIB_Y (LIB_Y_WRAPPER, say), and then link the main app against LIB_Y_WRAPPER.</p> <p>To try out my suggestion you will need to:</p> <ol> <li>Change your "static lib that handles all LIB_X stuff" from a static LIB project into a DLL project (which I will call LIB_X_WRAPPER).</li> <li>Make sure the header files of LIB_X_WRAPPER don't include any of the LIB_X header files. This is <em>really important</em> because the wrapper needs to completely isolate your app from the data types declared in the LIB_X header files (such as <code>std::vector&lt;double&gt;</code>). Only refer to LIB_X's header files from within the source files of LIB_X_WRAPPER.</li> <li>Change the declaration of all classes and functions in your static lib to ensure they are exported from the DLL (see <a href="https://stackoverflow.com/questions/538134/exporting-functions-from-a-dll-with-dllexport/538179#538179">this answer</a> if you need details about exporting from a DLL).</li> </ol> <p>This solution worked for me because it kept the instantiation (compiler generated functions) of the <code>std::vector&lt;std::string&gt;</code> class used by LIBY completely separate from the instantiation of <code>std::vector&lt;std::string&gt;</code> in my app.</p> <p>As an aside, I suspect the cause of the crash you are seeing (you comment it is in the destructor of <code>std::vector&lt;double&gt;</code>) is because the instantiation of <code>std::vector&lt;double&gt;</code> in your app is different to that in LIB_X.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COI was wondering if something like this would work, I'll try testing it out. My problem with this so far is #2, removing libx headers from the wrapper. I need data members from libx in my class, and they need the libx namespace for declaration. The variable might look like Libx::DataStructA _dataStructA; I can't create a class prototype because it requires the namespace, and I can't use the namespace because I don't have header access, but maybe there's something I don't know about when it comes to namespaces that can solve this?
      singulars
    2. COMore on my above comment, I'm not sure if it's about the namespace, it's just a forward declaration problem entirely on a number of levels. The libx class I'm trying to forward declare isn't declared as a pointer in my class, so it throws a fit about that for one thing. Declaring it as a pointer doesn't seem to help much.
      singulars
    3. COOK, after doing much screwing around and googling it looks like you can forward declare a class within a namespace like this: namespace LibX { class libxClass; } within the header so that I can later declare a LibX::libxClass. The problem I'm having now is that I'm getting redefinition errors. I have the libxClass.h file included in my .cpp file, and it complains about having a definition within my header and the libxClass.h files. On top of that, the 'class' I am trying to forward declare is actually a typedef of a class.. not sure what impact that has on the situation.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload