I am trying to write a simple test executable that links with the SGP4 library. However, I believe there is something wrong with how I've written my CMakeLists.txt. Configuration goes off without a hitch. However I get LNK2019: Unresolved external symbol...
errors during the build step.
I have used target_link_libraries
to point at each and every .lib
file, and target_include_directories
to point at the associated header files. There must be an additional step, or mistake I've made somewhere. What am I missing?
This is the file structure of my project:
sgp4_sandbox
├───test.cpp
├───CMakeLists.txt
├───build
└───Sgp4Prop
├───Documentation
├───Lib
│ └───Windows <-------------------- .lib and DLLs here
├───SampleCode
│ └───C
│ ├───DriverExamples
│ │ ├───OscVecToTLE
│ │ ├───services <------------------- HEADER FILES HERE
│ │ ├───Sgp4Prop
│ │ ├───Sgp4Prop_Simple
│ │ ├───ShowVersion
│ │ ├───TleReepoch
│ │ └───wrappers <------------------- HEADER FILES HERE
│ └───x64
│ └───Debug
├───UnitTests
├───Utilities
└───Verify
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(SGP4_sandbox
VERSION 0.1
DESCRIPTION "Sample project to play with sgp4"
LANGUAGES CXX
)
add_executable(test test.cpp)
set(SGP4_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Sgp4Prop/Lib/Windows")
target_include_directories(test
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Sgp4Prop/SampleCode/C/DriverExamples/wrappers"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/Sgp4Prop/SampleCode/C/DriverExamples/services")
target_link_libraries(test
PRIVATE ${SGP4_LIB_PATH}/AstroFunc.lib
PRIVATE ${SGP4_LIB_PATH}/DllMain.lib
PRIVATE ${SGP4_LIB_PATH}/ElOps.lib
PRIVATE ${SGP4_LIB_PATH}/EnvConst.lib
PRIVATE ${SGP4_LIB_PATH}/ExtEphem.lib
PRIVATE ${SGP4_LIB_PATH}/Obs.lib
PRIVATE ${SGP4_LIB_PATH}/SatState.lib
PRIVATE ${SGP4_LIB_PATH}/Sensor.lib
PRIVATE ${SGP4_LIB_PATH}/Sgp4prop.lib
PRIVATE ${SGP4_LIB_PATH}/SpVec.lib
PRIVATE ${SGP4_LIB_PATH}/TimeFunc.lib
PRIVATE ${SGP4_LIB_PATH}/Tle.lib
PRIVATE ${SGP4_LIB_PATH}/Vcm.lib)
My simple test.cpp, largely copied from some demo code:
#include <iostream>
// Compiler directive that allows C++ code to use the C header files
// Begin
#ifdef __cplusplus
extern "C"
{
#endif
#include <DllMainDll_Service.h>
#include <TimeFuncDll_Service.h>
#include <DllMainDll.h>
#include <EnvConstDll.h>
#include <AstroFuncDll.h>
#include <TimeFuncDll.h>
#include <TleDll.h>
#include <Sgp4PropDll.h>
// End compiler directive
#ifdef __cplusplus
}
#endif
// Forward declare loaders and free-ers
void LoadAstroStdDlls();
void FreeAstroStdDlls();
int main() {
LoadAstroStdDlls();
FreeAstroStdDlls();
}
// Load all the dlls being used in the program
void LoadAstroStdDlls()
{
// Load MainDll dll
LoadDllMainDll();
// Load EnvConst dll and assign function pointers
LoadEnvConstDll();
// Load TimeFunc dll and assign function pointers
LoadTimeFuncDll();
// Load AstroFunc dll and assign function pointers
LoadAstroFuncDll();
// Load TLE dll and assign function pointers
LoadTleDll();
// Load Sgp4Prop dll and assign function pointers
LoadSgp4PropDll();
}
// Free all the dlls being used in the program
void FreeAstroStdDlls()
{
// Free MainDll dll
FreeDllMainDll();
// Free EnvConst dll
FreeEnvConstDll();
// Free AstroFunc dll
FreeAstroFuncDll();
// Free TimeFunc dll
FreeTimeFuncDll();
// Free TLE dll
FreeTleDll();
// Free Sgp4Prop dll
FreeSgp4PropDll();
}
And finally, here is the output of calling cmake --build .
CMake is re-running because C:/Users/E40056742/projects/SGP4_sandbox/build/CMakeFiles/generate.stamp is out-of-date.
the file 'C:/Users/E40056742/projects/SGP4_sandbox/CMakeLists.txt'
is newer than 'C:/Users/E40056742/projects/SGP4_sandbox/build/CMakeFiles/generate.stamp.depend'
result='-1'
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/E40056742/projects/SGP4_sandbox/build
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Checking Build System
Building Custom Rule C:/Users/E40056742/projects/SGP4_sandbox/CMakeLists.txt
test.obj : error LNK2019: unresolved external symbol FreeDllMainDll referenced in function "void __cdecl FreeAstroStdDlls(void)" (?FreeAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol LoadDllMainDll referenced in function "void __cdecl LoadAstroStdDlls(void)" (?LoadAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol LoadEnvConstDll referenced in function "void __cdecl LoadAstroStdDlls(void)" (?LoadAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol FreeEnvConstDll referenced in function "void __cdecl FreeAstroStdDlls(void)" (?FreeAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol LoadAstroFuncDll referenced in function "void __cdecl LoadAstroStdDlls(void)" (?LoadAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol FreeAstroFuncDll referenced in function "void __cdecl FreeAstroStdDlls(void)" (?FreeAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol LoadTimeFuncDll referenced in function "void __cdecl LoadAstroStdDlls(void)" (?LoadAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol FreeTimeFuncDll referenced in function "void __cdecl FreeAstroStdDlls(void)" (?FreeAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol LoadTleDll referenced in function "void __cdecl LoadAstroStdDlls(void)" (?LoadAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol FreeTleDll referenced in function "void __cdecl FreeAstroStdDlls(void)" (?FreeAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol LoadSgp4PropDll referenced in function "void __cdecl LoadAstroStdDlls(void)" (?LoadAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
test.obj : error LNK2019: unresolved external symbol FreeSgp4PropDll referenced in function "void __cdecl FreeAstroStdDlls(void)" (?FreeAstroStdDlls@@YAXXZ) [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]
C:\Users\E40056742\projects\SGP4_sandbox\build\Debug\test.exe : fatal error LNK1120: 12 unresolved externals [C:\Users\E40056742\projects\SGP4_sandbox\build\test.vcxproj]