0

I have a CMake project that I use to generate a Visual Studio solution, which I then try to compile. For some reason, the library file after compilation is nonexistent. I've searched my entire project folder, and cannot find any library files. Here's my CMake setup:

Project root:

cmake_minimum_required(VERSION 3.22)
project(ShadowContainers)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

include_directories(include/)

add_subdirectory(library)

...

library subdirectory:

add_library(libShadows shadows.tpp ../include/shadows.hpp)
set_target_properties(libShadows PROPERTIES LINKER_LANGUAGE CXX) # a tpp and an hpp aren't enough to make the system certain it's c++
target_compile_features(libShadows PRIVATE cxx_std_23)

The MSbuild output contains these lines:

Done Building Project "C:\Users\[..]\projects\Shadow Array\library\libShadows.vcxproj" (default targets).

Done Building Project "C:\Users\[..]\projects\Shadow Array\library\libShadows.vcxproj.metaproj" (default targets).

Even if libShadows is the only target in my project, it's nowhere in my project directory.

Has anybody else had this experience? Any help is appreciated. Thanks!

Edit: To compile the project, I have tried:

My typical process (working directory = the project root):

cmake .
msbuild ShadowContainers.sln

An alternate process (working directory also project root):

mkdir build
cd build
cmake ..
cmake --build .

Both have produced the same result, albeit with VS and CMake files in different places. No library is outputted either way.

OCDkirby
  • 190
  • 9
  • @273K I run `cmake .` to configure the project, and `MSbuild.exe ShadowArrays.sln` to build. I've never run `cmake --build`. Project folder-wide searches for `libShadows.lib` or `liblibShadows.lib` both return nothing. – OCDkirby Jun 11 '22 at 00:09
  • You can print out the current binary directory in CMake to see where the output files would go, but the compiled files wouldn't normally be in the project directory, unless you meant project output directory. – ChrisMM Jun 11 '22 at 00:21
  • @273K cwd is the project root, or `C:\Users\[..]\projects\Shadow Arrays`. `C:\Users\[..]\projects\Shadow Arrays\ Debug` is empty. – OCDkirby Jun 11 '22 at 00:29
  • @ChrisMM by project folder-wide search, I mean recursively searching all directories inside the root. This includes the binary output dir and all other output dir variable paths. – OCDkirby Jun 11 '22 at 00:32
  • `"C:\Users\[..]\projects\Shadow Array\library\libShadows.vcxproj" ` having a space in a path can cause you build problems. Not sure if this is the case here. – drescherjm Jun 11 '22 at 00:52
  • @drescherjm I’ll try removing the space, I’ve never tried to build recursive projects using template c++ from a CMake project so far (standard linking to external dependencies with a space in the path works fine). – OCDkirby Jun 11 '22 at 00:57
  • I second the recommendation of `cmake --build .` One comment though. With the use of CMake you normally don't build in the same exact root folder as the source. Many projects would be something like `cd source && mkdir build && cd build && cmake ..` – drescherjm Jun 11 '22 at 01:06
  • @drescherjm I’ll also try deleting all my CMake files and doing that. – OCDkirby Jun 11 '22 at 01:11
  • @drescherjm I tried deleting all my cmake files and creating a build directory to `cmake ..` from, after either `cmake --build .` or `msbuild ShadowContainers.sln` no libraries or binaries to be found. Deleted build/ and renamed the project directory from Shadow Array to ShadowArray, tried the same thing, same result. – OCDkirby Jun 11 '22 at 01:18
  • Found the issue--I don't know how to work with template-only projects. It's not CMake or MSbuild related. – OCDkirby Jun 11 '22 at 01:37
  • Hi ,glad to know you've found the solution to resolve this issue! Please consider accepting it as an answer to change its status to Answered. See [can I answer my own question..](https://stackoverflow.com/help/self-answer), Just a reminder :) – Minxin Yu - MSFT Jun 13 '22 at 06:41
  • @MinxinYu-MSFT Thanks! I'm required to wait two days before accepting my own answer, which is today. – OCDkirby Jun 13 '22 at 17:16

1 Answers1

1

I was able to find the issue. CMake (and conventions for that matter) do not see a .tpp as a code file (similarly to how they treat header files). Thus, I was trying to compile a target with no legitimate code files. Template-only libraries are not libraries at all, so I should not be attempting to compile this standalone, and should instead put the .hpp and .tpp as the include in my projects!

OCDkirby
  • 190
  • 9
  • The error "CMake can not determine linker language for target" in 99% cases means that your library (or executable) has **no sources**: https://stackoverflow.com/questions/11801186/cmake-unable-to-determine-linker-language-with-c. In most cases such absence of sources signals about "something wrong with your CMakeLists.txt". By setting `LINKER_LANGUAGE` property you only suppress that signal but do not resolve the **actual problem**. – Tsyvarev Jun 11 '22 at 08:43