简体   繁体   English

MSYS2 CMake路径前缀为Windows格式(C:/),但需要MSYS2 / * nix样式(/ c /)进行链接

[英]MSYS2 CMake path prefix is in Windows format (C:/) but needs MSYS2/*nix style (/c/) to link

The CMake installed from pacman within MSYS2 seems to prefix library and header/include paths with C:/, but the actual path format needed is a prefix of /c/. 从MSYS2中的pacman安装的CMake似乎为库和标头/包含路径加上C:/前缀,但是实际所需的路径格式是/ c /前缀。 I've used a regex replace as a kludge but it's not a very elegant solution and I'm worried this will break things like MingW. 我已经使用正则表达式替换来解决问题,但这不是一个很好的解决方案,我担心这会破坏MingW之类的东西。

Just for reference the library path being obtianed by CMake is: 仅供参考,CMake修改的库路径为:

 C:/msys64/mingw64/include/gtk-3.0;C:/msys64/mingw64/include/cairo;C:/msys64/mingw64/include;C:/msys64/mingw64/include/pango-1.0;C:/msys64/mingw64/include/fribidi;C:/msys64/mingw64/include;C:/msys64/mingw64/include/atk-1.0;C:/msys64/mingw64/include/cairo;C:/msys64/mingw64/include/pixman-1;C:/msys64/mingw64/include;C:/msys64/mingw64/include/freetype2;C:/msys64/mingw64/include;C:/msys64/mingw64/include/harfbuzz;C:/msys64/mingw64/include/libpng16;C:/msys64/mingw64/include/gdk-pixbuf-2.0;C:/msys64/mingw64/include/libpng16;C:/msys64/mingw64/include;C:/msys64/mingw64/lib/libffi-3.2.1/include;C:/msys64/mingw64/include/glib-2.0;C:/msys64/mingw64/lib/glib-2.0/include;C:/msys64/mingw64/include

and it needs to be: 它必须是:

 /c//msys64/mingw64/include/gtk-3.0;/c//msys64/mingw64/include/cairo;/c//msys64/mingw64/include;/c//msys64/mingw64/include/pango-1.0;/c//msys64/mingw64/include/fribidi;/c//msys64/mingw64/include;/c//msys64/mingw64/include/atk-1.0;/c//msys64/mingw64/include/cairo;/c//msys64/mingw64/include/pixman-1;/c//msys64/mingw64/include;/c//msys64/mingw64/include/freetype2;/c//msys64/mingw64/include;/c//msys64/mingw64/include/harfbuzz;/c//msys64/mingw64/include/libpng16;/c//msys64/mingw64/include/gdk-pixbuf-2.0;/c//msys64/mingw64/include/libpng16;/c//msys64/mingw64/include;/c//msys64/mingw64/lib/libffi-3.2.1/include;/c//msys64/mingw64/include/glib-2.0;/c//msys64/mingw64/lib/glib-2.0/include;/c//msys64/mingw64/include

I've been digging for a solution and saw that CMake for Windows (not the CMake installed from within MSYS2) has a MSYS specific makefile generator, but there must be some simple solution to use the CMake available within MSYS2. 我一直在寻找解决方案,发现用于Windows的CMake(不是从MSYS2中安装的CMake)具有特定于MSYS的Makefile生成器,但是必须有一些简单的解决方案才能使用MSYS2中可用的CMake。 I can't imagine I'm the only one who's encountered this issue. 我无法想象我是唯一遇到此问题的人。 Does anyone know of a clean solution? 有人知道干净的解决方案吗?

UPDATE: Here is the CMakeLists.txt without the regex replace hack. 更新:这是CMakeLists.txt,没有使用正则表达式替换hack。 This fails with the error 失败并显示错误

C:/msys64/home/username/sample/src/main.cpp:1:10 fatal error: gtk/gtk.h: No such file or directory
 #include <gtk/gtk.h>

compilation terminated.

during make. 在制作期间。


    cmake_minimum_required(VERSION 3.12)

    project(sample CXX)

    # Find GTK+ headers/libs with PkgConfig
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

    include_directories(${GTK3_INCLUDE_DIRS})
    link_directories(${GTK3_LIBRARY_DIRS})

    add_definitions(${GTK3_CFLAGS_OTHER})

    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/natives)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/natives)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

    add_executable(sample src/main.cpp)

    target_link_libraries(sample ${GTK3_LIBRARIES})

For main.cpp just use the default GTK+ hello world 对于main.cpp,只需使用默认的GTK + hello world


    #include <gtk/gtk.h>

    int
    main (int   argc,
    char *argv[])
    {
      GtkWidget *window;

      gtk_init (&argc, &argv);

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

      g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

      gtk_widget_show (window);

      gtk_main ();

      return 0;
    }

To make compilation work, I'm using the following CMake kludge: 为了使编译工作正常进行,我使用以下CMake kludge:


    cmake_minimum_required(VERSION 3.12)

    project(sample CXX)

    # Find GTK+ headers/libs with PkgConfig
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

    # Generated paths starting with "C:" need to be converted to /c/ to work with MSYS2
    # TODO remove this or do it some way better at some point in the future
    if(MSYS OR MINGW)
        string(REGEX REPLACE "C:" "/c/" GTK3_INCLUDE_DIRS "${GTK3_INCLUDE_DIRS}")
    endif(MSYS OR MINGW)

    include_directories(${GTK3_INCLUDE_DIRS})
    link_directories(${GTK3_LIBRARY_DIRS})

    add_definitions(${GTK3_CFLAGS_OTHER})

    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/natives)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/natives)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

    add_executable(sample src/main.cpp)

    target_link_libraries(sample ${GTK3_LIBRARIES})

Note the REGEX REPLACE. 注意REGEX REPLACE。

Another thing to note is I'm only using tools, such as cmake, and libraries/headers/etc. 要注意的另一件事是,我仅使用诸如cmake之类的工具,以及库/标头/等。 installed from pacman within MSYS2 and I'd prefer to keep it that way because I'll be rolling something out based on this as a Ruby native extension and the Windows SDK for that is MSYS2 based. 它是从pacman安装在MSYS2中的,所以我宁愿保持这种方式,因为我将基于此作为Ruby本机扩展推出一些东西,而Windows SDK则基于MSYS2。 At the same time, I'm fairly sure my kludge will break MingW based builds (if I even need to worry about that?) and it's not very flexible. 同时,我相当确定我的想法会破坏基于MingW的版本(如果我什至需要担心这一点吗?),它也不是很灵活。

The problem has to do with how MingW packages are/were ported to MSYS2. 问题与将MingW软件包移植到MSYS2有关。 The paths are in "Windows" format for backwards compatibility and to preserve compatibility with systems like Visual Studio. 路径采用“ Windows”格式,以实现向后兼容性并保持与Visual Studio等系统的兼容性。 The only answer is to do regex replace like I've pointed out above or to just recompile the libraries in MSYS2 like I've now chosen to do. 唯一的答案是像我上面指出的那样进行正则表达式替换,或者像现在选择的那样重新编译MSYS2中的库。

As a general guideline, packages available in MSYS2 without mingw prefixes in the package names don't have this "backward compatibility" issue and, as far as I know, don't require such a workaround. 作为一般准则,软件包名称中没有mingw前缀的MSYS2中可用的软件包不存在此“向后兼容性”问题,据我所知,不需要这种解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM