Я новенький в C ++ Программирование и выбор проекта с открытым исходным кодом с C ++. < /p>
Инструменты, которые я использую: < /p>
vscode < /li>
vs 2019 инструменты. /> vcpkg < /li>
msvc < /li>
< /ol>
Команды сборки, которые я выполняю: < /p>
Код: Выделить всё
cmake .. -DSHIPPING=ON -G "Visual Studio 16 2019" -DCMAKE_TOOLCHAIN_FILE="D:\Program Files\vcpkg\scripts\buildsystems\vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows
< /code>
cmake --build . --config=Release
< /code>
During the building process, I met this error:
app.obj : error LNK2019: unresolved external symbol "private: unsigned \__int64 \__cdecl App::EstimatePlySizeMB(void)" (?EstimatePlySizeMB@App@@AEAA_KXZ)
referenced in function "private: void \__cdecl App::PreloadGaussianClouds(void)" (?PreloadGaussianClouds@App@@AEAAXXZ)
D:\\td-project\\3d-player\\build\\Release\\3d-player-refined.exe : fatal error LNK1120: 1 unresolved externals
< /code>
I checked the EstimatePlySizeMBКод: Выделить всё
// app.cpp
App::App(MainContext& mainContextIn):
mainContext(mainContextIn)
{
// some code
}
size_t App::EstimatePlySizeMB()
{
std::ifstream file(this->plyFiles[0], std::ios::binary | std::ios::ate);
if (!file.is_open())
{
return 200;
}
size_t sizeBytes = static_cast(file.tellg());
return sizeBytes / (1024 * 1024);
}
void App::PreloadGaussianClouds()
{
if (this->plyFiles.empty())
{
return;
}
size_t singlePlySizeMB = this->EstimatePlySizeMB();
// other codes...
< /code>
At the beginning, I guessed maybe there was something wrong in the implementation of this function. So, instead, I rewrote this function, just like:
// app.cpp
size_t App::EstimatePlySizeMB()
{
return 200;
}
< /code>
But surprisingly, after I rewrote this function as above, I deleted the build directory and went rebuild. Still, the same error took place.
In addition, I tried to rename this function, App::EstimatePlySizeMBКод: Выделить всё
// app.h
class App
{
//... other codes
private:
size_t EstimatePlySizeMB()
{
std::ifstream file(this->plyFiles[0], std::ios::binary | std::ios::ate);
if (!file.is_open())
{
return 200;
}
size_t sizeBytes = static_cast(file.tellg());
return sizeBytes / (1024 * 1024);
}
// other codes
}
< /code>
Any recommandation and comment is highly appreciated. I have been stuck here for a very long time. Thanks in advance.
Thanks again for the community. I put #error "Testing if app.cpp is compiled"Код: Выделить всё
#include "app.h"
#error "Testing if app.cpp is compiled"
#ifndef __ANDROID__
#define USE_SDL
#include
#endif
#ifdef USE_SDL
#include
#endif
#include
#include
#include
#include
#include
#include
< /code>
Then, I run cmake --build . --config=ReleaseТерминал показывает:
Код: Выделить всё
D:\td-project\3d-player\src\app.cpp(8,1): fatal error C1189: #error: "Testing if app.cpp is compiled" [D:\td-project\
3d-player\build\3d-player-refined.vcxproj]
< /code>
So maybe it is certain that app.cpp< /code> должен быть скомпилирован? То, что я делаю, просто перемещает приложение :: atimateplysizemb // app.cpp
App::App(MainContext& mainContextIn):
mainContext(mainContextIn)
{
// some code
}
void App::PreloadGaussianClouds()
{
if (this->plyFiles.empty())
{
return;
}
size_t singlePlySizeMB = this->EstimatePlySizeMB();
// other codes...
size_t App::EstimatePlySizeMB()
{
std::ifstream file(this->plyFiles[0], std::ios::binary | std::ios::ate);
if (!file.is_open())
{
return 200;
}
size_t sizeBytes = static_cast(file.tellg());
return sizeBytes / (1024 * 1024);
}
< /code>
Now it works but I don't know what happened.
Подробнее здесь: https://stackoverflow.com/questions/797 ... ntation-bu
Мобильная версия