# cmake shows -static-libstdc++ file missing when it existed on the LINUX system.

**URL:** https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028
**Category:** Usage
**Tags:** os:linux
**Created:** [September 21, 2023, 4:42am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028 "2023-09-21T04:42:44Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 21, 2023, 4:42am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/1 "2023-09-21T04:42:44Z")

</div>

Below code failed to run, why? How to fix?  
– Performing Test STATIC\_SYSTEM\_LIBS  
– Performing Test STATIC\_SYSTEM\_LIBS - Failed

```
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-z,defs")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
  check_cxx_source_runs("int main() { return 0; }" STATIC_SYSTEM_LIBS)
  if (NOT STATIC_SYSTEM_LIBS)
     message(WARNING "You are missing one or more static system libraries that will be linked by -static-libgcc -static-libstdc++")
  endif()

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 24, 2023, 12:39am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/2 "2023-09-24T00:39:43Z")

</div>

There should be more context about the error in `CMakeFiles/CMakeError.log` or the like (they should all be under that directory though).

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 25, 2023, 10:02pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/3 "2023-09-25T22:02:29Z")

</div>

There are no such log existed. below are all the file lists:  
cmake.check\_cache  
Makefile.cmake  
Makefile2  
nfiq2api.dir  
progress.marks  
nfiq2.dir  
OpenCV.dir  
TargetDirectories.txt  
CMakeRuleHashes.txt  
CMakeDirectoryInformation.cmake  
CMakeConfigureLog.yaml  
CMakeScratch  
3.26.3  
feature\_tests.bin  
pkgRedirects

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 25, 2023, 10:03pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/4 "2023-09-25T22:03:35Z")

</div>

> [@indianscorpion](#):
>
> ```auto
> set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
> check_cxx_source_runs("int main() { return 0; }" STATIC_SYSTEM_LIBS)
> if (NOT STATIC_SYSTEM_LIBS)
> message(WARNING "You are missing one or more static system libraries that will be linked by -static-libgcc -static-libstdc++")
> endif()
> 
> ```

When I extracted that above part and run that alone, it works.  
But when it embedded in a big CMakeLists.txt, it simple fails.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 25, 2023, 11:00pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/5 "2023-09-25T23:00:18Z")

</div>

> [@indianscorpion](#):
>
> When I extracted that above part and run that alone, it works.  
> But when it embedded in a big CMakeLists.txt, it simple fails.

Can you try adding other parts of the “big” CMake code piece by piece until it breaks? That should get us a simpler test case to look at.

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 25, 2023, 11:55pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/6 "2023-09-25T23:55:52Z")

</div>

Thanks for the fast responses Ben.  
Actually I am just building the NFIQ2 library from gitHub.

> **[GitHub - usnistgov/NFIQ2: Optical live-scan and ink fingerprint image quality...](https://github.com/usnistgov/NFIQ2)**
>
> Optical live-scan and ink fingerprint image quality assessment tool - GitHub - usnistgov/NFIQ2: Optical live-scan and ink fingerprint image quality assessment tool

I am following the step below, but failed.  
git clone --recursive [GitHub - usnistgov/NFIQ2: Optical live-scan and ink fingerprint image quality assessment tool](https://github.com/usnistgov/NFIQ2.git)  
cd NFIQ2  
mkdir build  
cd build  
cmake … -DBUILD\_NFIQ2\_CLI=OFF  
cmake --build .

is it possible for you to try it in your env?  
Many thanks,  
Joe

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 26, 2023, 12:34am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/7 "2023-09-26T00:34:08Z")

</div>

On my machine, I see:

```auto
    buildResult:
      variable: "STATIC_SYSTEM_LIBS_COMPILED"
      cached: true
      stdout: |
        Change Dir: '/home/boeckb/misc/code/NFIQ2/build/CMakeFiles/CMakeScratch/TryCompile-BmQw0N'
        
        Run Build Command(s): /home/boeckb/.local/bin/ninja -v cmTC_29159
        [1-1->1/2@52.6] /usr/lib64/ccache/c++ -DSTATIC_SYSTEM_LIBS -o CMakeFiles/cmTC_29159.dir/src.cxx.o -c /home/boeckb/misc/code/NFIQ2/build/CMakeFiles/CMakeScratch/TryCompile-BmQw0N/src.cxx
        [0-1->2/2@74.1] : && /usr/lib64/ccache/c++ -static-libgcc -static-libstdc++ -rdynamic CMakeFiles/cmTC_29159.dir/src.cxx.o -o cmTC_29159 && :
        FAILED: cmTC_29159 
        : && /usr/lib64/ccache/c++ -static-libgcc -static-libstdc++ -rdynamic CMakeFiles/cmTC_29159.dir/src.cxx.o -o cmTC_29159 && :
        /usr/bin/ld: cannot find -lstdc++: No such file or directory
        collect2: error: ld returned 1 exit status
        ninja: build stopped: subcommand failed.
        
      exitCode: 1

```

in `CMakeFiles/CMakeConfigureLog.yaml`. I indeed do not have the static libraries installed.

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 26, 2023, 12:42am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/8 "2023-09-26T00:42:37Z")

</div>

On my, I saw CMakeFiles/CMakeConfigureLog.yaml:  
But if I try the code snippet on the first comment, I got success! How to fix?

buildResult:  
variable: “STATIC\_SYSTEM\_LIBS\_COMPILED”  
cached: true  
stdout: |  
Change Dir: /home/autobld/j/NFIQ2/build/CMakeFiles/CMakeScratch/TryCompile-iK37Wm

```
    Run Build Command(s):/opt/cmake-3.26.3-linux-x86_64/bin/cmake -E env VERBOSE=1 /usr/bin/gmake -f Makefile cmTC_dd0d2/fast && /usr/bin/gmake -f CMakeFiles/cmTC_dd0d2.dir/build.make CMakeFiles/cmTC_dd0d2.dir/build
    gmake[1]: Entering directory `/home/autobld/j/NFIQ2/build/CMakeFiles/CMakeScratch/TryCompile-iK37Wm'
    Building CXX object CMakeFiles/cmTC_dd0d2.dir/src.cxx.o
    /usr/bin/c++ -DSTATIC_SYSTEM_LIBS -o CMakeFiles/cmTC_dd0d2.dir/src.cxx.o -c /home/autobld/j/NFIQ2/build/CMakeFiles/CMakeScratch/TryCompile-iK37Wm/src.cxx
    Linking CXX executable cmTC_dd0d2
    /opt/cmake-3.26.3-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/cmTC_dd0d2.dir/link.txt --verbose=1
    /usr/bin/c++ -static-libgcc -static-libstdc++ -rdynamic CMakeFiles/cmTC_dd0d2.dir/src.cxx.o -o cmTC_dd0d2
    /usr/bin/ld: cannot find -lstdc++
    collect2: error: ld returned 1 exit status
    gmake[1]: *** [cmTC_dd0d2] Error 1
    gmake[1]: Leaving directory `/home/autobld/j/NFIQ2/build/CMakeFiles/CMakeScratch/TryCompile-iK37Wm'
    gmake: *** [cmTC_dd0d2/fast] Error 2

  exitCode: 2
runResult:
  variable: "STATIC_SYSTEM_LIBS_EXITCODE"
  cached: true

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 26, 2023, 1:20am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/9 "2023-09-26T01:20:12Z")

</div>

That doesn’t look like success to me. Where is it saying that it succeeded?

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 26, 2023, 3:44am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/10 "2023-09-26T03:44:58Z")

</div>

Make the CMakeLists.txt as simple as below:

```cmake
include(CheckCXXSourceRuns)
cmake_minimum_required(VERSION 3.5)
project(HelloWorld C CXX)
include_directories(${PROJECT_SOURCE_DIR})
add_executable(hello hello.cpp)
add_executable(hello2 hello.c)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-z,defs")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
check_cxx_source_runs ("int main() { return 0; }" STATIC_SYSTEM_LIBS)
if (NOT STATIC_SYSTEM_LIBS)
    message(WARNING "You are missing one or more static system libraries that will be linked by -static-libgcc -static-libstdc++")
endif()

```

hello.c

```plaintext
#include "stdio.h"

int main()
{
    printf("this is just a test\n");
    return 0;
}

```

hello.cpp:

```c++
#include <iostream>

int main()
{
    for (int i = 0; i < Times; i++)
    {
        std::cout << "Hello, world!" << std::endl;
    }
    return 0;
}

```

and run `cmake -B build .`  
and it got successs.  
Can you please try the above?

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [September 26, 2023, 4:27am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/11 "2023-09-26T04:27:53Z")

</div>

Is it really expected to work to compile the hello2 **C** program with a **C++** -specific compiler argument like -static-libstdc++ ?

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [September 26, 2023, 4:33am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/12 "2023-09-26T04:33:02Z")

</div>

You did not set CMAKE\_REQUIRED\_LINK\_OPTIONS as needed for check\_cxx\_source\_runs() to test something useful.

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 26, 2023, 5:01am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/13 "2023-09-26T05:01:11Z")

</div>

I think so, the core library is c++, but it will be exposed as C API as well.

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 26, 2023, 5:01am UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/14 "2023-09-26T05:01:51Z")

</div>

It was running OK in my test env for this example.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 26, 2023, 1:34pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/15 "2023-09-26T13:34:25Z")

</div>

> [@indianscorpion](#):
>
> and run `cmake -B build .`  
> and it got successs.

Ok, so the build worked. Did the configure check for the static system libraries pass?

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 26, 2023, 5:10pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/16 "2023-09-26T17:10:42Z")

</div>

> [@ben.boeckel](#):
>
> for the static s

Yes, now the question is why it failed on NFIQ2 source code build? I extracted that part of code and it succeeded as both of us tested. Why failed there?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 26, 2023, 5:45pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/17 "2023-09-26T17:45:23Z")

</div>

It did not pass for me; I also saw `– Performing Test STATIC_SYSTEM_LIBS - Failed` because I do not have the libraries referenced installed on my machine.

---

<div class="post-metadata">

### Author: ![indianscorpion](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/i/d78d45/32.png) [@indianscorpion](https://discourse.cmake.org/u/indianscorpion)
#### Post date: [September 27, 2023, 5:19pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/18 "2023-09-27T17:19:53Z")

</div>

Can you please install and try it again?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 27, 2023, 5:30pm UTC](https://discourse.cmake.org/t/cmake-shows-static-libstdc-file-missing-when-it-existed-on-the-linux-system/9028/19 "2023-09-27T17:30:00Z")

</div>

I have yet to see any output that shows the `try_compile` succeeding on your setup. You’ve said it builds, but this does not mean the `try_compile` worked as it only raises a warning, not an error.
