Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could NOT find X11 (missing: X11_X11_LIB) #1957

Closed
wangshucheng opened this issue Aug 30, 2021 · 21 comments
Closed

Could NOT find X11 (missing: X11_X11_LIB) #1957

wangshucheng opened this issue Aug 30, 2021 · 21 comments
Assignees
Labels
bug Bug reports and bugfix pull requests build Build file bugs and PRs (not compilation errors) cannot reproduce Bugs that have failed verification external Issues GLFW cannot reasonably solve X11
Milestone

Comments

@wangshucheng
Copy link

wangshucheng@wangshucheng:/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build$ sudo apt-get install libx11-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libx11-dev is already the newest version (2:1.6.9-2ubuntu1.2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

wangshucheng@wangshucheng:/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build$ cmake ..
-- Using X11 for window creation
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find X11 (missing: X11_X11_LIB)
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindX11.cmake:366 (find_package_handle_standard_args)
CMakeLists.txt:203 (find_package)

-- Configuring incomplete, errors occurred!
See also "/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build/CMakeFiles/CMakeOutput.log".
See also "/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build/CMakeFiles/CMakeError.log".

wangshucheng@wangshucheng:/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build$ sudo apt-cache search x11-dev
libx11-dev - X11 client-side library (development headers)
libxkbcommon-x11-dev - library to create keymaps with the XKB X11 protocol - development files
libghc-gi-gdkx11-dev - GDKX11 bindings
libghc-x11-dev - Haskell X11 binding for GHC
libnx-x11-dev - nxagent's libNX_X11 client-part library (development headers)
librust-cairo-sys-rs+x11-dev - FFI bindings to libcairo - feature "x11"
librust-x11-dev - X11 library bindings for Rust - Rust source code

@elmindreda elmindreda added build Build file bugs and PRs (not compilation errors) X11 labels Aug 30, 2021
@elmindreda elmindreda self-assigned this Aug 30, 2021
@elmindreda
Copy link
Member

I'm not sure exactly what is causing the error above but you probably want to install the full xorg-dev package if you haven't already, not just libx11-dev. GLFW needs the headers from several other packages brought in by xorg-dev in order to build.

If the problem remains with that package installed then that's definitely a bug somewhere.

@wangshucheng
Copy link
Author

I'm not sure exactly what is causing the error above but you probably want to install the full xorg-dev package if you haven't already, not just libx11-dev. GLFW needs the headers from several other packages brought in by xorg-dev in order to build.

If the problem remains with that package installed then that's definitely a bug somewhere.

root@wangshucheng:/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build# sudo apt-get install xorg-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
xorg-dev is already the newest version (1:7.7+19ubuntu14).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Thank you for your answer. But I think xorg-dev is also completely installed.

@wangshucheng wangshucheng reopened this Aug 31, 2021
@elmindreda elmindreda added bug Bug reports and bugfix pull requests external Issues GLFW cannot reasonably solve help needed Issues needing more contributors to solve cannot reproduce Bugs that have failed verification labels Aug 31, 2021
@elmindreda
Copy link
Member

You're running Ubuntu on WSL?

I don't think I've ever seen CMake fail to find X11 installed from the regular packages on a Debian derived system so I really don't know what could be causing this.

@Velaseriat
Copy link

oof. I'm on the same boat with WSL2. I guess it's a WSL thing.

@elmindreda
Copy link
Member

It could be a WSL thing but also I use WSL daily for building and testing the X11 backend and have not seen this issue.

@LeonFretter
Copy link

For me this happened when trying to compile with clang. With gcc it worked fine.
Can anyone maybe try reproducing with clang?

@aosterthun
Copy link

aosterthun commented Jan 28, 2022

For me this happened when trying to compile with clang. With gcc it worked fine. Can anyone maybe try reproducing with clang?

Same thing here. In my setup I am using CMake with CMake Presets. My CMakePresets.json looks as follows:

{
    "version": 2,
    "configurePresets": [
        {
            "name": "LLVM",
            "displayName": "LLVM Toolchain",
            "description": "Using compilers: C = /home/oste_ar/tools/llvm-project/build/bin/clang, CXX = /home/oste_ar/tools/llvm-project/build/bin/clang",
            "generator": "Unix Makefiles",
            "binaryDir": "${sourceDir}/build",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "/home/oste_ar/tools/llvm-project/build/bin/clang",
                "CMAKE_CXX_COMPILER": "/home/oste_ar/tools/llvm-project/build/bin/clang++",
                "CMAKE_C_LINK_EXECUTABLE": "/home/oste_ar/tools/llvm-project/build/bin/ld.lld",
                "CMAKE_CXX_LINK_EXECUTABLE": "/home/oste_ar/tools/llvm-project/build/bin/ld.lld"
            }
        },
        {
            "name": "gcc",
            "displayName": "GCC 11.2.0 x86_64-linux-gnu",
            "description": "Using compilers: C = /bin/x86_64-linux-gnu-gcc-11, CXX = /bin/x86_64-linux-gnu-g++-11",
            "generator": "Unix Makefiles",
            "binaryDir": "${sourceDir}/build",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "/bin/x86_64-linux-gnu-gcc-11",
                "CMAKE_CXX_COMPILER": "/bin/x86_64-linux-gnu-g++-11"
            }
        }
    ]
}

As you can see I have two presets. One for gcc and one for clang. When I compile glfw with the gcc preset I have no problems at all. When I switch to clang I get an error during the cmake configuration process:

[main] Building folder: raviscpp 
[main] Configuring folder: raviscpp 
[proc] Executing command: /usr/bin/cmake -DCMAKE_C_COMPILER=/home/oste_ar/tools/llvm-project/build/bin/clang -DCMAKE_CXX_COMPILER=/home/oste_ar/tools/llvm-project/build/bin/clang++ -DCMAKE_C_LINK_EXECUTABLE=/home/oste_ar/tools/llvm-project/build/bin/ld.lld -DCMAKE_CXX_LINK_EXECUTABLE=/home/oste_ar/tools/llvm-project/build/bin/ld.lld -H/home/oste_ar/Development/private/raviscpp -B/home/oste_ar/Development/private/raviscpp/build -G "Unix Makefiles"
[cmake] -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
[cmake] -- Using X11 for window creation
[cmake] CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
[cmake]   Could NOT find X11 (missing: X11_X11_LIB)
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
[cmake]   /usr/share/cmake-3.18/Modules/FindX11.cmake:414 (find_package_handle_standard_args)
[cmake]   build/_deps/glfw-src/CMakeLists.txt:208 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/oste_ar/Development/private/raviscpp/build/CMakeFiles/CMakeOutput.log".

I compiled the llvm project in my user directory and pointing to the clang and lld executables in the cmake preset.

For me it is quite confusing that this issue is happening during the cmake configuration process. For me the only reasonable explanation is that cmake gets the path it searches for libraries in from the compiler itself. That would explain why this happens when I switch the compiler but shows up as an issue during cmake configuration.

@Seratna
Copy link

Seratna commented Mar 6, 2022

I used cmake 3.22.3 and ran into the same problem. I switched back to cmake 3.21.6 and every thing is OK.

@lucasjinreal
Copy link

Damn it. Got same errro here. I have installed libxorg-dev libx11-dev everything it needed, but glfw just can not found it.

Any solution? Mine cmake 3.22.3

@lucasjinreal
Copy link

btw, downgrade or upgrade cmake doesn't help at all.

@elmindreda
Copy link
Member

I don't know why CMake is failing to find libX11.so on some systems. That should possibly be reported to CMake.

In the meantime, if you know where the library is on your system you should be able to work around this issue with CMAKE_LIBRARY_PATH by adding -DCMAKE_LIBRARY_PATH=/path/to/lib on the CMake command-line.

@lucasjinreal
Copy link

For anyone got this error, recommend using cmake -DGLFW_USE_WAYLAND=ON .. and it works

works like a charm. And what even more strangely, if using this, it will found x11 again......

@ben-clayton
Copy link

ben-clayton commented May 5, 2022

This issue appears to be reproducible with Clang 14, but not with Clang 12 (!?)

Update: Clang 13 also works (non-reproducable)

@lucasjinreal
Copy link

Damn it! Now cmake -DGLFW_USE_WAYLAND=ON .. doesn't work on same machine....... same env................. Just another time...............

I am really doubt this logic ,this X11 thing, it's just like a strange shit.

@lucasjinreal
Copy link

OK, I found the problem, the f**k guilty guy behind it was anaconda.....

this guy just hide all lib from my system.... Be note even if you deactivated it, it still effect your system.

@xthexder
Copy link

xthexder commented Jul 6, 2022

This issue appears to be reproducible with Clang 14, but not with Clang 12 (!?)

Same issue here,
I'm able to reproduce with Clang 14.0.0 + CMake 3.20.4, but not with GCC or older Clang versions (12 and 13 tested).

@BrandonPacewic
Copy link

BrandonPacewic commented Jul 12, 2022

For me this happened when trying to compile with clang. With gcc it worked fine. Can anyone maybe try reproducing with clang?

Same thing here. In my setup I am using CMake with CMake Presets. My CMakePresets.json looks as follows:

{
    "version": 2,
    "configurePresets": [
        {
            "name": "LLVM",
            "displayName": "LLVM Toolchain",
            "description": "Using compilers: C = /home/oste_ar/tools/llvm-project/build/bin/clang, CXX = /home/oste_ar/tools/llvm-project/build/bin/clang",
            "generator": "Unix Makefiles",
            "binaryDir": "${sourceDir}/build",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "/home/oste_ar/tools/llvm-project/build/bin/clang",
                "CMAKE_CXX_COMPILER": "/home/oste_ar/tools/llvm-project/build/bin/clang++",
                "CMAKE_C_LINK_EXECUTABLE": "/home/oste_ar/tools/llvm-project/build/bin/ld.lld",
                "CMAKE_CXX_LINK_EXECUTABLE": "/home/oste_ar/tools/llvm-project/build/bin/ld.lld"
            }
        },
        {
            "name": "gcc",
            "displayName": "GCC 11.2.0 x86_64-linux-gnu",
            "description": "Using compilers: C = /bin/x86_64-linux-gnu-gcc-11, CXX = /bin/x86_64-linux-gnu-g++-11",
            "generator": "Unix Makefiles",
            "binaryDir": "${sourceDir}/build",
            "cacheVariables": {
                "CMAKE_C_COMPILER": "/bin/x86_64-linux-gnu-gcc-11",
                "CMAKE_CXX_COMPILER": "/bin/x86_64-linux-gnu-g++-11"
            }
        }
    ]
}

As you can see I have two presets. One for gcc and one for clang. When I compile glfw with the gcc preset I have no problems at all. When I switch to clang I get an error during the cmake configuration process:

[main] Building folder: raviscpp 
[main] Configuring folder: raviscpp 
[proc] Executing command: /usr/bin/cmake -DCMAKE_C_COMPILER=/home/oste_ar/tools/llvm-project/build/bin/clang -DCMAKE_CXX_COMPILER=/home/oste_ar/tools/llvm-project/build/bin/clang++ -DCMAKE_C_LINK_EXECUTABLE=/home/oste_ar/tools/llvm-project/build/bin/ld.lld -DCMAKE_CXX_LINK_EXECUTABLE=/home/oste_ar/tools/llvm-project/build/bin/ld.lld -H/home/oste_ar/Development/private/raviscpp -B/home/oste_ar/Development/private/raviscpp/build -G "Unix Makefiles"
[cmake] -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
[cmake] -- Using X11 for window creation
[cmake] CMake Error at /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
[cmake]   Could NOT find X11 (missing: X11_X11_LIB)
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.18/Modules/FindPackageHandleStandardArgs.cmake:458 (_FPHSA_FAILURE_MESSAGE)
[cmake]   /usr/share/cmake-3.18/Modules/FindX11.cmake:414 (find_package_handle_standard_args)
[cmake]   build/_deps/glfw-src/CMakeLists.txt:208 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/oste_ar/Development/private/raviscpp/build/CMakeFiles/CMakeOutput.log".

I compiled the llvm project in my user directory and pointing to the clang and lld executables in the cmake preset.

For me it is quite confusing that this issue is happening during the cmake configuration process. For me the only reasonable explanation is that cmake gets the path it searches for libraries in from the compiler itself. That would explain why this happens when I switch the compiler but shows up as an issue during cmake configuration.

For me regardless of which compiler I use the issue still persists.

[driver] Switching to configure preset: gcc
[driver] Switching to build preset: __defaultBuildPreset__
[main] Configuring folder: Ionic 
[proc] Executing command: /usr/bin/cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/gcc -S/home/brandon/documents/Ionic -B/home/brandon/documents/Ionic/build -G "Unix Makefiles"
[cmake] -- The CXX compiler identification is GNU 9.4.0
[cmake] -- Check for working CXX compiler: /usr/bin/gcc
[cmake] -- Check for working CXX compiler: /usr/bin/gcc -- works
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- The C compiler identification is GNU 9.4.0
[cmake] -- Check for working C compiler: /usr/bin/gcc
[cmake] -- Check for working C compiler: /usr/bin/gcc -- works
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Looking for pthread.h
[cmake] -- Looking for pthread.h - found
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
[cmake] -- Found Threads: TRUE  
[cmake] -- Found Doxygen: /usr/bin/doxygen (found version "1.8.17") found components: doxygen 
[cmake] -- Including X11 support
[cmake] CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
[cmake]   Could NOT find X11 (missing: X11_X11_LIB)
[cmake] Call Stack (most recent call first):
[cmake]   /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
[cmake]   /usr/share/cmake-3.16/Modules/FindX11.cmake:366 (find_package_handle_standard_args)
[cmake]   glfw/src/CMakeLists.txt:187 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "/home/brandon/documents/Ionic/build/CMakeFiles/CMakeOutput.log".

I am on Ubuntu 20.0.1. The more I look at this issue the more I think it is related to CMake or the debian os.

Source code here.

Update:

This problem only occurs for me when I am using a compiler other than gcc OR I am trying to compile my project, which then compiles glfw. If I open a standalone glfw project everything works as intended with gcc.

Another update FIXED:

I fixed the problem by just including the libglfw3.a file and compiling the projects separately. For some reason this fixed the problem completely so there must have been a problem with my CMake setup.

@binbinJiaYou
Copy link

wangshucheng@wangshucheng:/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build$ sudo apt-get install libx11-dev Reading package lists... Done Building dependency tree Reading state information... Done libx11-dev is already the newest version (2:1.6.9-2ubuntu1.2). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

wangshucheng@wangshucheng:/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build$ cmake .. -- Using X11 for window creation CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message): Could NOT find X11 (missing: X11_X11_LIB) Call Stack (most recent call first): /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake-3.16/Modules/FindX11.cmake:366 (find_package_handle_standard_args) CMakeLists.txt:203 (find_package)

-- Configuring incomplete, errors occurred! See also "/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build/CMakeFiles/CMakeOutput.log". See also "/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build/CMakeFiles/CMakeError.log".

wangshucheng@wangshucheng:/mnt/c/Users/wangsc/Downloads/glfw/glfw-3.3.4/build$ sudo apt-cache search x11-dev libx11-dev - X11 client-side library (development headers) libxkbcommon-x11-dev - library to create keymaps with the XKB X11 protocol - development files libghc-gi-gdkx11-dev - GDKX11 bindings libghc-x11-dev - Haskell X11 binding for GHC libnx-x11-dev - nxagent's libNX_X11 client-part library (development headers) librust-cairo-sys-rs+x11-dev - FFI bindings to libcairo - feature "x11" librust-x11-dev - X11 library bindings for Rust - Rust source code

你可以试一下这个:
https://blog.csdn.net/qq_39845665/article/details/125462900

@ben-clayton
Copy link

TL;DR: My issues went away after updating to CMake to v3.24.1.

If that still doesn't work, consider setting CMAKE_LIBRARY_PATH to include the path to X11 in your application's CMakeLists.txt.


I spent some time investigating why clang-12 works and clang-14 doesn't. These are my findings:

X11_X11_LIB is set in FindX11.cmake, by using CMake's find_library command. FindX11.cmake has a hardcoded list of search paths, however on my system (ubuntu 21.04) libX11.so was found at /usr/lib/x86_64-linux-gnu/libX11.so, which isn't part of this list.

The documentation for find_library() states that it falls back to searching at <prefix>/lib/<arch> if CMAKE_LIBRARY_ARCHITECTURE is set.

Low and behold, CMAKE_LIBRARY_ARCHITECTURE is different between clang-12 and clang-14:

  • clang-12: CMAKE_LIBRARY_ARCHITECTURE=x86_64-linux-gnu
  • clang-14: CMAKE_LIBRARY_ARCHITECTURE=x86_64-unknown-linux-gnu

I tried digging further into where CMAKE_LIBRARY_ARCHITECTURE was set, and quickly found that this had all been changed since my build of CMake. I grabbed a newer build, and magically the X11 issue is now gone.

@mikejsavage
Copy link

If you're building from glfw master you don't need libx11.so present anymore. This still fails but you can just do cmake -DX11_X11_LIB=who_cares" as a workaround

@elmindreda elmindreda removed the help needed Issues needing more contributors to solve label Jan 14, 2024
@elmindreda
Copy link
Member

With the findings of @ben-clayton above, I believe this can be closed as a resolved external bug.

@elmindreda elmindreda added this to the None milestone Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports and bugfix pull requests build Build file bugs and PRs (not compilation errors) cannot reproduce Bugs that have failed verification external Issues GLFW cannot reasonably solve X11
Projects
None yet
Development

No branches or pull requests