0

I'm trying to create a server with OmniORB and I want to create several shared_ptrs. But When I do this I get the following 2 error

error LNK2019: unresolved external symbol __imp__invalid_parameter referenced in function "public: class std::shared_ptr<struct SharedPtr_i::Vector2> & __cdecl std::array<class std::shared_ptr<struct SharedPtr_i::Vector2>,1000>::operator[](unsigned __int64)" (??A?$array@V?$shared_ptr@UVector2@SharedPtr_i@@@std@@$0DOI@@std@@QEAAAEAV?$shared_ptr@UVector2@SharedPtr_i@@@1@_K@Z)
error LNK2019: unresolved external symbol __imp__CrtDbgReport referenced in function "public: class std::shared_ptr<struct SharedPtr_i::Vector2> & __cdecl std::array<class std::shared_ptr<struct SharedPtr_i::Vector2>,1000>::operator[](unsigned __int64)" (??A?$array@V?$shared_ptr@UVector2@SharedPtr_i@@@std@@$0DOI@@std@@QEAAAEAV?$shared_ptr@UVector2@SharedPtr_i@@@1@_K@Z)

I'm aware that most of these "unresolved external symbols" are caused by forgetting to import a *.lib file. However to my knownedge my code doesn't require an extra .lib file.

This is the code that is causing the issue for me:

#include "pch.h"
#include <array>
#include "sharedPtr.hh"

class SharedPtr_i : public POA_SharedPtr
{
private:
    struct Vector2
    {
        float x, y;
    };
public:
    inline SharedPtr_i() {}
    virtual ~SharedPtr_i() {}
    void CreateSharedPtr();
};

void SharedPtr_i::CreateSharedPtr()
{
    std::array<std::shared_ptr<Vector2>, 1000 > sharedPtrs;
    for (int i = 0; i < sharedPtrs.size(); i++)
    {
        sharedPtrs[i] = std::shared_ptr<Vector2>(new Vector2()); // This line caused the error
    }
}

In my testing I found out that the brackets ([ ]) are causing the error, but how do brackets cause an unresolved external symbol error?

any advice on how to solve the issue is greatly appreciated.

wes
  • 379
  • 3
  • 15
  • It's hard to reason about code where much is hidden in headers and not in the question - you should create a [mcve], together with its compile and link commands. – Toby Speight Oct 10 '19 at 14:02
  • @TobySpeight How do you mean? The sharedPtr.hh is just a interface that I need for the server and client. I can share it with you, but I have not made it my self. the hh file is generated via the IDL compiler. Everything else is just server handeling stuff and is in the main() function. No problems right there. – wes Oct 10 '19 at 14:06
  • *how do brackets cause an unresolved external symbol error?* Did you read the name of the symbol (`__imp__invalid_parameter`)? – Ken White Oct 10 '19 at 16:14
  • You have 2 different linker errors. Check out this link for the first error. It seems you have inconsistencies in your debug mode project setup i.e. different flags etc. https://social.msdn.microsoft.com/Forums/vstudio/en-US/7234ea2b-0042-42ed-b4e2-5d8644dfb57d/unresolved-external-symbol-invalidparameternoinfo?forum=vclanguage – Sisir Oct 10 '19 at 17:48
  • Check this for the 2nd error. Again same, may be few flags or macros are inconsistent with your project setup. https://stackoverflow.com/questions/6003368/unresolved-externals-in-c-when-using-vectors-and-find/6004441 – Sisir Oct 10 '19 at 17:49
  • 1
    @Sisir Thank you! I'm running on Debug (x64) and selected **Multi-threaded DLL** instead of **Multi-threaded Debug DLL** in **C/C++ -> Code Generation**. – wes Oct 11 '19 at 10:20

1 Answers1

0

As pointed out in the comment Linker errors related to __imp__invalid_parameter and __imp__CrtDbgReport appear when the project is built i debug mode and the other setup like macros/flags are inconsistent with it.

Sisir
  • 4,584
  • 4
  • 26
  • 37