NatronGitHub / Natron

Open-source video compositing software. Node-graph based. Similar in functionalities to Adobe After Effects and Nuke by The Foundry.
http://NatronGitHub.github.io
GNU General Public License v2.0
4.56k stars 333 forks source link

Defined functions in KnobImpl.h cause errors #804

Closed a01163125 closed 2 years ago

a01163125 commented 2 years ago

Hi, I found a list of errors of unresolved external symbols like:

Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol
"public: enum Natron::KnobHelper::ValueChangedReturnCodeEnum __cdecl Natron::Knob
<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >
::setValue(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >
const &,class Natron::ViewSpec,int,bool)"
(?setValue@?$Knob@V?$basic_string@DU?$char_traits@D@std@
@V?$allocator@D@2@@std@
@@Natron@@QEAA?AW4ValueChangedReturnCodeEnum@KnobHelper@2@AEBV
?$basic_string@DU?$char_traits@D@std@
@V?$allocator@D@2@@std@@VViewSpec@2@H_N@Z)
Engine D:\Users\Source\Repos\Natron\Engine\AppInstance.obj 1

I am using Visual Studio 2019 on Win10 with Natron 2.5.

I am sure that it is a commonsense no defining functions in H file as this behaviour will cause "already defined" error when this function been called from more than one file. However I found that KnobImpl.h implemented many methods of Knob.h and only been included by Knob.cpp and when I compile it I found many 2001 errors. So how can I solve this problem? Should I change this into a cpp file or did I missed any settings in VS?

devernay commented 2 years ago

Those are template functions, so they definitely fit inside a header file. Knob.obj should have this symbol definition Knob<string>::setValue(const string&,...), since Knob.cpp ends with explicit template instantiations:

template class Knob<int>;
template class Knob<double>;
template class Knob<bool>;
template class Knob<std::string>;

Can you check if Knob.obj contains these symbols?

a01163125 commented 2 years ago

Those are template functions, so they definitely fit inside a header file. Knob.obj should have this symbol definition Knob<string>::setValue(const string&,...), since Knob.cpp ends with explicit template instantiations:

template class Knob<int>;
template class Knob<double>;
template class Knob<bool>;
template class Knob<std::string>;

Can you check if Knob.obj contains these symbols?

Thank you! I have solved this problem by copying functions into H file. And engine is a lib instead of exe project. I forgot to close this question. And, how can I check if Knob.obj contains these symbols?

YakoYakoYokuYoku commented 2 years ago

And, how can I check if Knob.obj contains these symbols?

Simply you can use dumpbin from the MSVC toolkit or llvm-nm from LLVM/Clang. Closing since this question was solved.