i'm trying to build clang with mingw-w64 on windows (10), so i followed this tutorial : https://here-be-braces.com/blog/llvm-clang-on-windows-mingw-revisited
but cmake don't recognise gcc as an C++11 compiler. I run cmake with this command :
cmake C:\llvm -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_TOOLS=ON -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS="-IC:/mingw64/x86_64-w64-mingw32/include" -DGCC_INSTALL_PREFIX=%syspath% -DCMAKE_INSTALL_PREFIX=%syspath% -DCMAKE_EXE_LINKER_FLAGS="-lmingw32 -static-libgcc -static-libstdc++ -static -lstdc++ -lm -lpthread -lgcc -lmsvcrt -lmoldname -lgcc_eh -lkernel32 -luser32 -ladvapi32 -liconv -lmingwex" -DBUILD_SHARED_LIBS=OFF -DLLVM_PARALLEL_COMPILE_JOBS=2 -DLLVM_PARALLEL_LINK_JOBS=2 -DCMAKE_INCLUDE_PATH="C:/mingw64/x86_64-w64-mingw32/include" -DGCC_INSTALL_PREFIX="C:/mingw64" -DCMAKE_LIBRARY_PATH="C:/mingw64/x86_64-w64-mingw32/lib"
I obtened the list of librairies with "gcc -v test.c -Wl,--verbose", test.c is just an classic hello world. But with the libmingw32, I get this error :
cmd.exe /C "cd . && C:\mingw64\bin\gcc.exe -lmingw32 -static-libgcc
-static-libstdc++ -static -lstdc++ -lm -lpthread -lgcc -lmsvcrt -lmoldname
-lgcc_eh -lkernel32 -luser32 -ladvapi32 -liconv -lmingwex
CMakeFiles/cmTC_3b639.dir/testCCompiler.c.obj -o cmTC_3b639.exe
-Wl,--out-implib,libcmTC_3b639.dll.a
-Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32
-lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32
-ladvapi32 && cd ."
CMakeFiles/cmTC_3b639.dir/testCCompiler.c.obj:testCCompiler.c:(.text+0x0):
multiple definition of `main'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x0):
first defined here
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e):
undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Without it, i get further, but i get this : http://pastebin.com/zeMViHzA
CMake Error at projects/libcxx/CMakeLists.txt:423 (message):
C++11 or greater is required but the compiler does not support c++11
How can i get rid of the "WinMain undefined reference" for the cmake tests ?
edit : the gcc version : 6.2.0
Related
I'm trying to build a simple application
using the freetype library on Windows 64.
Freetype lib was compiled from src on windows 64
simple programm
#include <ft2build.h>
#include FT_FREETYPE_H
int main (int argc, char** argv) {
FT_Library ft;
if (FT_Init_FreeType(&ft) != 0) {
//err
}
}
Added environment variable FREETYPE_DIR
and cmake script
cmake_minimum_required(VERSION 3.22)
cmake_path(CONVERT $ENV{COMPILER} TO_CMAKE_PATH_LIST COMPILER)
set(CMAKE_CXX_COMPILER "${COMPILER}/clang++.exe")
set(CMAKE_C_COMPILER "${COMPILER}/clang.exe")
set(CMAKE_RC_COMPILER "${COMPILER}/llvm-rc.exe")
set(CMAKE_BUILD_TYPE Release)
set(EXECUTABLE_OUTPUT_PATH "../bin")
project (text)
file(GLOB SRC
"./src/main.cpp"
)
find_package(Freetype MODULE REQUIRED)
add_executable (${PROJECT_NAME} ${SRC})
target_include_directories(${PROJECT_NAME}
PRIVATE "./include"
PRIVATE ${FREETYPE_INCLUDE_DIRS}
)
target_link_libraries(${PROJECT_NAME}
Freetype::Freetype
)
but I'm stuck, get a linker error, although freetype library is linked
ninja: Entering directory `./build'
[1/1] cmd.exe /C "cd . &&
C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\Llvm\x64\bin\CLANG_~1.EXE -fuse-ld=lld-link
-nostartfiles -nostdlib -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -
Xlinker /subsystem:console CMakeFiles/text.dir/src/main.cpp.obj -o
D:\git\cpp\opengl\drawtext\bin\text.exe -Xlinker /MANIFEST:EMBED -Xlinker
/implib:D:\git\cpp\opengl\drawtext\bin\text.lib -Xlinker
/pdb:D:\git\cpp\opengl\drawtext\bin\text.pdb -Xlinker /version:0.0 D:/source/freetype-
2.12.1/build/x86_64/Release/lib/freetype.lib -lkernel32 -luser32 -lgdi32 -lwinspool -
lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
FAILED: D:/git/cpp/opengl/drawtext/bin/text.exe
cmd.exe /C "cd . &&
C:\PROGRA~2\MICROS~2\2022\BUILDT~1\VC\Tools\Llvm\x64\bin\CLANG_~1.EXE -fuse-ld=lld-link
-nostartfiles -nostdlib -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt -
Xlinker /subsystem:console CMakeFiles/text.dir/src/main.cpp.obj -o
D:\git\cpp\opengl\drawtext\bin\text.exe -Xlinker /MANIFEST:EMBED -Xlinker
/implib:D:\git\cpp\opengl\drawtext\bin\text.lib -Xlinker
/pdb:D:\git\cpp\opengl\drawtext\bin\text.pdb -Xlinker /version:0.0 D:/source/freetype-
2.12.1/build/x86_64/Release/lib/freetype.lib -lkernel32 -luser32 -lgdi32 -lwinspool -
lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
lld-link: error: undefined symbol: FT_Init_FreeType
>>> referenced by CMakeFiles/text.dir/src/main.cpp.obj:(main)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Find the workaround, recompile freetype lib via Microsoft cl.exe instead of clang.
I'm trying to set to glew but cant seem to get it to work any tips im using cmake with clion?
here is my cmake file:
cmake_minimum_required(VERSION 3.21)
project(openglAttempt)
set(CMAKE_CXX_STANDARD 14)
include_directories(${PROJECT_SOURCE_DIR}/GPU/include)
include_directories(GLEW/include)
link_directories(${PROJECT_SOURCE_DIR}/GPU/lib-mingw-w64)
link_directories(GLEW/lib/Release/Win32)
add_compile_definitions(glew_Static)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} glfw3 opengl32 gdi32)
and here is the error message:
FAILED: openglAttempt.exe
cmd.exe /C "cd . && C:\PROGRA~1\JETBRA~1\CLION2~1.2\bin\mingw\bin\G__~1.EXE -g CMakeFiles/openglAttempt.dir/main.cpp.obj -o openglAttempt.exe -Wl,--out-implib,libopenglAttempt.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -LC:/Users/nathan/CLionProjects/openglAttempt/GPU/lib-mingw-w64 -LC:/Users/nathan/CLionProjects/openglAttempt/GLEW/lib/Release/Win32 -lglfw3 -lopengl32 -lgdi32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:\Program Files\JetBrains\CLion 2021.3.2\bin\mingw\bin/ld.exe: CMakeFiles/openglAttempt.dir/main.cpp.obj:C:/Users/nathan/CLionProjects/openglAttempt/main.cpp:26: undefined reference to `__imp_glewInit'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
I've been trying to add SDL2 library to a program, but I keep getting this error:
'SDL.h' file not found
Here's the cmake file:
cmake_minimum_required(VERSION 3.22)
project(test)
list(APPEND CMAKE_PREFIX_PATH "C:/Users/Windows 10/CLionProjects/test/SDL2/i686-w64-
mingw32/SDL2/i686-w64-mingw32/include/SDL2")
find_package(SDL2 REQUIRED)
set(CMAKE_CXX_STANDARD 14)
add_executable(test main.cpp)
target_include_directories(test PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(test PRIVATE ${SDL2_LIBRARIES})
message(STATUS IncludeDir=${SDL2_INCLUDE_DIRS} )
message(STATUS IncludeLib=${SDL2_LIBRARIES})
The cmake output after regen is:
-- IncludeDir=/opt/local/i686-w64-mingw32/include/SDL2
-- IncludeLib=-L/opt/local/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Windows 10/CLionProjects/test/cmake-build-debug
Here is a picture of the project's structure, and a picture of the include directory, the SDL2 directory entirely is included in the project files.
The include folder has all the header files and contain SDL.h which makes this odd because the compiler should be able to find it.
I'm using the CLion IDE and MinGW compiler.
This project is a test project to add SDL2 and make it work, thus I only have the main class and it contains this:
#include "SDL.h"
int main() {
return 0;
}
Edit: I changed the include to give the full path to SDL.h so main is:
#include "SDL2/i686-w64-mingw32/include/SDL2/SDL.h"
int main() {
return 0;
}
So the file is found but when I run it the following error appears:
[1/2] Building CXX object CMakeFiles/test.dir/main.cpp.obj
[2/2] Linking CXX executable test.exe
FAILED: test.exe
cmd.exe /C "cd . && "D:\Clion\CLion 2022.1\bin\mingw\bin\g++.exe" -g
CMakeFiles/test.dir/main.cpp.obj -o test.exe -Wl,--out-implib,libtest.dll.a
-Wl,--major-image-version,0,--minor-image-version,0 -L/opt/local/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -lmingw32 -lSDL2main -lSDL2 -mwindows -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
D:\Clion\CLion 2022.1\bin\mingw\bin/ld.exe: cannot find -lSDL2main
D:\Clion\CLion 2022.1\bin\mingw\bin/ld.exe: cannot find -lSDL2
D:\Clion\CLion 2022.1\bin\mingw\bin/ld.exe: cannot find -lSDL2main
D:\Clion\CLion 2022.1\bin\mingw\bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Second Edit:
After changing CMAKE_VERBOSE_MAKEFILE, the build log again is:
"D:\Clion\CLion 2022.1\bin\cmake\win\bin\cmake.exe" --build "C:\Users\Windows 10\CLionProjects\test\cmake-build-debug" --target test
[1/2] "D:\Clion\CLion 2022.1\bin\mingw\bin\g++.exe" -I/opt/local/i686-w64-mingw32/include/SDL2 -g -std=gnu++14 -MD -MT CMakeFiles/test.dir/main.cpp.obj -MF CMakeFiles\test.dir\main.cpp.obj.d -o CMakeFiles/test.dir/main.cpp.obj -c "C:/Users/Windows 10/CLionProjects/test/main.cpp"
[2/2] cmd.exe /C "cd . && "D:\Clion\CLion 2022.1\bin\mingw\bin\g++.exe" -g CMakeFiles/test.dir/main.cpp.obj -o test.exe -Wl,--out-implib,libtest.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/opt/local/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
FAILED: test.exe
cmd.exe /C "cd . && "D:\Clion\CLion 2022.1\bin\mingw\bin\g++.exe" -g CMakeFiles/test.dir/main.cpp.obj -o test.exe -Wl,--out-implib,libtest.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L/opt/local/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
D:\Clion\CLion 2022.1\bin\mingw\bin/ld.exe: cannot find -lSDL2main
D:\Clion\CLion 2022.1\bin\mingw\bin/ld.exe: cannot find -lSDL2
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Changing back to include "SDL.h" only and running on the same cmake config gives this:
"D:\Clion\CLion 2022.1\bin\cmake\win\bin\cmake.exe" --build
"C:\Users\Windows 10\CLionProjects\test\cmake-build-debug" --target test
[1/2] "D:\Clion\CLion 2022.1\bin\mingw\bin\g++.exe" -I/opt/local/i686-w64-mingw32/include/SDL2 -g -std=gnu++14 -MD -MT CMakeFiles/test.dir/main.cpp.obj -MF CMakeFiles\test.dir\main.cpp.obj.d -o CMakeFiles/test.dir/main.cpp.obj -c "C:/Users/Windows 10/CLionProjects/test/main.cpp"
FAILED: CMakeFiles/test.dir/main.cpp.obj
"D:\Clion\CLion 2022.1\bin\mingw\bin\g++.exe" -I/opt/local/i686-w64-mingw32/include/SDL2 -g -std=gnu++14 -MD -MT CMakeFiles/test.dir/main.cpp.obj -MF CMakeFiles\test.dir\main.cpp.obj.d -o CMakeFiles/test.dir/main.cpp.obj -c "C:/Users/Windows 10/CLionProjects/test/main.cpp"
C:/Users/Windows 10/CLionProjects/test/main.cpp:1:10: fatal error: SDL.h: No such file or directory
1 | #include "SDL.h"
| ^~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
Like what #Someprogrammerdude said the include directory is being set as /opt/local/i686-w64-mingw32/include/SDL2 instead of the actual path C:/Users/Windows 10/CLionProjects/test/SDL2/i686-w64-mingw32/SDL2/i686-w64-mingw32/include/SDL2
I'm trying to make the minimal sample for wxWidgets. I'm getting the following output:
$ mingw32-make -f makefile.gcc
g++ -c -o gcc_mswud\minimal_minimal.o -g -O0 -mthreads -DHAVE_W32API_H -D__WXMS
W__ -D_UNICODE -I.\..\..\lib\gcc_lib\mswud -I.\..\..\include -W -Wall -I
. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -MTgcc_mswud\minimal_min
imal.o -MFgcc_mswud\minimal_minimal.o.d -MD -MP minimal.cpp
g++ -o gcc_mswud\minimal.exe gcc_mswud\minimal_sample_rc.o gcc_mswud\minimal_min
imal.o -g -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows
-lwxmsw29ud_core -lwxbase29ud -lwxtiffd -lwxjpegd -lwxpngd -lwxzlibd -lwxreg
exud -lwxexpatd -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -ls
hell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lwini
net
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxmsw29ud_core
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxbase29ud
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxtiffd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxjpegd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxpngd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxzlibd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxregexud
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxexpatd
collect2.exe: error: ld returned 1 exit status
makefile.gcc:222: recipe for target 'gcc_mswud\minimal.exe' failed
mingw32-make: *** [gcc_mswud\minimal.exe] Error 1
For some reason I cannot find the wxwidgets libraries; I think I may have set some environment variable up incorrectly or perhaps I should have moved them to /mingw/lib?
Could someone help me track this down or point me in the right direction, I'd really appreciate it.
Thanks!
You have told gcc to link the wxWidget libraries but haven't told it where to find them.
Just add -Lc:/your_wxwidget_path to the command line options for for the linker and it should link.
Did you build wxWidgets libraries as explained in the MinGW section of the documentation? It looks like the linker can't find the libraries because they are simply not there -- which would seem to indicate that you didn't build them. You need to do this first, before building the samples.
I dont understand why g++ cannot find getnameinfo in ws2_32, nm shows that it is there. Here is the output:
$ I:/Programs/MinGW/msys/1.0/bin/sh.exe ../libtool --tag=CXX --mode=link g++
-g -O2 -no-undefined -version-info 16:0:0 -o libetpan.la -rpath /i/Programs/M
inGW/lib dummy.lo versioninfo.lo data-types/libdata-types.la low-level/liblow-l
evel.la driver/libdriver.la main/libmain.la engine/libengine.la windows/libarch
.la -L/i/Programs/MinGW/lib -lws2_32 -liconv
libtool: link: rm -fr .libs/libetpan.dll.a
libtool: link: g++ -shared -nostdlib i:/programs/mingw/bin/../lib/gcc/mingw32/4.
7.0/../../../dllcrt2.o i:/programs/mingw/bin/../lib/gcc/mingw32/4.7.0/crtbegin.o
.libs/dummy.o .libs/versioninfo.o -Wl,--whole-archive data-types/.libs/libdat
a-types.a low-level/.libs/liblow-level.a driver/.libs/libdriver.a main/.libs/lib
main.a engine/.libs/libengine.a windows/.libs/libarch.a -Wl,--no-whole-archive
-lws2_32 -lws2_32 -lws2_32 -lws2_32 -lws2_32 -lws2_32 -L/i/Programs/MinGW/lib -l
ws2_32 /mingw/lib/libiconv.dll.a -Li:/programs/mingw/bin/../lib/gcc/mingw32/4.7.
0 -Li:/programs/mingw/bin/../lib/gcc -Li:/programs/mingw/bin/../lib/gcc/mingw32/
4.7.0/../../../../mingw32/lib -Li:/programs/mingw/bin/../lib/gcc/mingw32/4.7.0/.
./../.. -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi3
2 -lshell32 -luser32 -lws2_32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmi
ngwex -lmsvcrt i:/programs/mingw/bin/../lib/gcc/mingw32/4.7.0/crtend.o -O2 -p
thread -o .libs/libetpan-16.dll -Wl,--enable-auto-image-base -Xlinker --out-impl
ib -Xlinker .libs/libetpan.dll.a
Creating library file: .libs/libetpan.dll.a
Warning: resolving _closesocket by linking to _closesocket#4
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
low-level/.libs/liblow-level.a(mailsmtp.o): In function `get_hostname':
c:\libetpan-00c7589\src\low-level\smtp/mailsmtp.c:266: undefined reference to `_
getnameinfo'
collect2.exe: error: ld returned 1 exit status
$ nm /i/Programs/MinGW/lib/libws2_32.a | grep getnameinfo
00000000 I __imp__getnameinfo#28
00000000 T _getnameinfo#28
I needed to #define _WIN32_WINNT 0x0501