c++ - LNK2019 error but Intellisense works fine -


i have native c++ unit test project throwing lnk2019 error every function call in project under test. surprisingly though, intellisense works fine!

the project under test static library (.lib) comprised of single public static function (type , member names have been changed protect innocent):

type.h

#pragma once  #include <string>  using namespace std;  namespace n {     enum class resultcode { undefined, a, b, c};       class mytype     {     public:         static void getresult(string id, string metadata, resultcode result);     }; } 

type.cpp

#include "pch.h" #include "type.h"  namespace n {     void mytype::getresult(string id, string metadata, n::resultcode result)     {         // implementation     } } 

my unit test project (a .dll) not use header file tests. i'm using google test framework. here source:

test.cpp

#include <pch.h> #include <gtest/gtest.h> #include <gtesthelpers/gtesthelpers.h> #include <mytype.h>  class mytypeunittests : public testing::test {};  test(mytypeunittests, foo) {     std::string metadata;      n::resultcode result = n::resultcode::undefined;     n::mytype::getresult("1234", metadata, result);     assert_true(result == n::resultcode::a); } 

when compile mytype, fine. , when wrote test, intellisense provided me signature getresult. when compile:

test.obj : error lnk2019: unresolved external symbol "public: static void __cdecl n:mytype:getresult(class std::basic_string,class std::allocator >,class std::basic_string,class std::allocator >, enum n::resultcode)" ... referenced in function ...

i have modified test project properties that:

  • vc++ directories > include directories includes reference directory containing mytype.h;
  • vc++ directories > reference directories includes reference directory containing mytype.lib;

i have confirmed under project dependencies test project, project under test checked. used undname verify function name specified in error matches name in .h , .cpp.

finally created new static parameterless function in mytype, , tried calling test (so rule out problem enum parameter) no dice. have followed instructions on msdn page linked above, , i'm out of ideas.

how can go resolving this?

edit: showing namespace block in cpp.

this problem:

using namespace n;  void mytype::getresult(string id, string metadata, n::resultcode result) {     // implementation } 

you should wrap definition namespace:

namespace n {  void mytype::getresult(string id, string metadata, n::resultcode result) {     // implementation }  } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -