vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.88k stars 2.17k forks source link

Tetris Build Errors Windows 7 #3398

Closed coruscateor closed 4 years ago

coruscateor commented 4 years ago

V 0.1.24 06f581e Windows 7 x64

What did you do? Try to build the tetris example after downloading the freetype Windows binaries into ...\v\thirdparty\freetype

What did you expect to see? Successful compilation

What did you see instead?

...\v\examples\tetris>v tetris.v
...\AppData\Local\Temp\v\tetris.tmp.c:140:9: warning: 'UNICODE' macro redefined [-Wmacro-redefined]
#define UNICODE
        ^
<command line>:1:9: note: previous definition is here
#defin...
(Use `v -g` to print the entire error message)

V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

...\v\examples\tetris>v -g tetris.v
C compiler=gcc
...\v\examples\tetris\tetris.v:536:9: warning: 'UNICODE' macro redefined [-Wmacro-redefined]
#define UNICODE
        ^
<command line>:1:9: note: previous definition is here
#define UNICODE 1
        ^
...\v\vlib\builtin\builtin.v:115:58: warning: incompatible pointer types passing 'int *' to parameter of type 'LPDWORD' (aka 'unsigned long *') [-Wincompatible-pointer-types]
 WriteConsole ( output_handle ,  wide_str ,  wide_len ,  & bytes_written ,  0 ) ;
                                                         ^~~~~~~~~~~~~~~
C:\llvm-mingw\include\wincon.h:264:122: note: passing argument to parameter 'lpNumberOfCharsWritten' here
  WINBASEAPI WINBOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput,CONST VOID *lpBuffer,DWORD nNumberOfCharsToWrite,LPDWORD lpNumberOfCharsWritten,LPVOID lpReserved);
                                                                                                                         ^
...\v\vlib\builtin\builtin.v:117:58: warning: incompatible pointer types passing 'int *' to parameter of type 'LPDWORD' (aka 'unsigned long *') [-Wincompatible-pointer-types]
 WriteFile ( output_handle , (char*) s .str ,  s .len ,  & bytes_written ,  0 ) ;
                                                         ^~~~~~~~~~~~~~~
C:\llvm-mingw\include\fileapi.h:179:109: note: passing argument to parameter 'lpNumberOfBytesWritten' here
  WINBASEAPI WINBOOL WINAPI WriteFile (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
                                                                                                            ^
...\v\vlib\gl\gl.v:15:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'int' [-Wint-conversion]
void* ok= gladLoadGL ( ) ;
      ^   ~~~~~~~~~~~~~~
...\v\vlib\gl\gl.v:43:34: warning: incompatible pointer types passing 'byte **' (aka 'unsigned char **') to parameter of type 'const GLchar *const *' (aka 'const char *const *') [-Wincompatible-pointer-types]
 glShaderSource ( shader ,  a ,  & source .str ,  b ) ;
                                 ^~~~~~~~~~~~~
...\v\vlib\gl\gl.v:43:51: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const GLint *' (aka 'const int *'); take the address with & [-Wint-conversion]
 glShaderSource ( shader ,  a ,  & source .str ,  b ) ;
                                                  ^
                                                  &
...\v\vlib\gl\gl.v:77:45: warning: passing 'byte [512]' to parameter of type 'GLchar *' (aka 'char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGetShaderInfoLog ( shader ,  512 ,  0 ,  info_log ) ;
                                            ^~~~~~~~
...\v\vlib\gl\gl.v:83:48: warning: passing 'byte [1024]' to parameter of type 'GLchar *' (aka 'char *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGetProgramInfoLog ( program ,  1024 ,  0 ,  info_log ) ;
                                               ^~~~~~~~
...\v\vlib\gl\gl.v:147:43: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
 glDrawElements ( mode ,  count ,  typ ,  indices ) ;
                                          ^~~~~~~
...\v\vlib\gl\gl.v:177:74: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
 glVertexAttribPointer ( index ,  size ,  typ ,  normalized ,  stride ,  ptr ) ;
                                                                         ^~~
...\v\vlib\strconv\atof.v:145:24: warning: overlapping comparisons always evaluate to false [-Wtautological-overlap-compare]
return  ( ( x >= 0x89  &&  x <= 0x13 )  ||  x == 0x20 ) == 1 ;
            ~~~~~~~~~~~^~~~~~~~~~~~~
...\v\vlib\os\os.v:652:63: warning: incompatible pointer types passing 'int *' to parameter of type 'LPDWORD' (aka 'unsigned long *') [-Wincompatible-pointer-types]
 ReadConsole ( h_input , (char*) buf ,  max_line_chars * 2 ,  & bytes_read ,  0 ) ;
                                                              ^~~~~~~~~~~~
C:\llvm-mingw\include\wincon.h:262:114: note: passing argument to parameter 'lpNumberOfCharsRead' here
  WINBASEAPI WINBOOL WINAPI ReadConsoleW(HANDLE hConsoleInput,LPVOID lpBuffer,DWORD nNumberOfCharsToRead,LPDWORD lpNumberOfCharsRead,LPVOID lpReserved);
                                                                                                                 ^
...\v\vlib\os\os.v:658:52: warning: incompatible pointer types passing 'int *' to parameter of type 'LPDWORD' (aka 'unsigned long *') [-Wincompatible-pointer-types]
bool res= ReadFile ( h_input , (char*) pos ,  1 ,  & bytes_read ,  0 ) ;
                                                   ^~~~~~~~~~~~
C:\llvm-mingw\include\fileapi.h:171:106: note: passing argument to parameter 'lpNumberOfBytesRead' here

  WINBASEAPI WINBOOL WINAPI ReadFile (HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
                                                                                                         ^
...\v\vlib\glfw\glfw.v:250:14: warning: initializing 'GLFWvidmode *' (aka 'struct GLFWvidmode *') with an expression of type 'const GLFWvidmode *' (aka 'const struct GLFWvidmode *') discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
GLFWvidmode* mode= glfwGetVideoMode ( glfwGetPrimaryMonitor ( ) ) ;
             ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...\v\vlib\glm\glm.v:254:31: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 0 ]/*rf32 1*/  =  1 ;
                              ^  ~
...\v\vlib\glm\glm.v:255:31: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 5 ]/*rf32 1*/  =  1 ;
                              ^  ~
...\v\vlib\glm\glm.v:256:32: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 10 ]/*rf32 1*/  =  1 ;
                               ^  ~
...\v\vlib\glm\glm.v:261:32: warning: incompatible integer to pointer conversion assigning to 'f32 *' (aka 'float *') from 'int' [-Wint-conversion]
 res [/*ptr!*/ 15 ]/*rf32 1*/  =  1 ;
                               ^  ~
...\v\vlib\freetype\freetype.v:116:23: warning: passing 'int *' to parameter of type 'GLuint *' (aka 'unsigned int *') converts between pointers to integer types with different sign [-Wpointer-sign]
 glGenTextures ( 1 ,  & texture ) ;
                      ^~~~~~~~~
...\v\vlib\freetype\freetype.v:168:7: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'FT_Error' (aka 'int') [-Wint-conversion]
void* ret= FT_Init_FreeType ( & ft ) ;
      ^    ~~~~~~~~~~~~~~~~~~~~~~~~~
...\v\vlib\freetype\freetype.v:188:7: warning: incompatible integer to pointer conversion assigning to 'void *' from 'int' [-Wint-conversion]
 ret  =  ((int)( FT_New_Face ( ft , (char*) font_path .str ,  0 ,  & face ) ) ) ;
      ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...\v\examples\tetris\tetris.v:154:226: warning: variable 'game' is uninitialized when used within its own initialization [-Wuninitialized]
Game* game= (Game*)memdup(&(Game) { .gg =  gg__new_context ( (gg__Cfg) { .width =  main__WinWidth , .height =  main__WinHeight , .use_ortho =  1 , .create_window =  1 , .window_title =  tos3("V Tetris") , .window_user_ptr =  game , .retina =  0 , .resizable =  0 , .font_size =  0 , .font_path =  tos3("") , .always_on_top =  0 , .scale =  0 } ) , .ft =  freetype__new_context ( (gg__Cfg) { .width =  main__WinWidth , .height =  main__WinHeight , .use_ortho =  1 , .font_size =  18 , .scale =  2 , .window_user_ptr =  0 , .retina =  0 , .resizable =  0 , .font_path =  tos3("") , .create_window =  0 , .window_title =  tos3("") , .always_on_top =  0 , } ) , .score =  0 , .pos_x =  0 , .pos_y =  0 , .field =  new_array(0, 1, sizeof( array_int )) , .tetro
=  new_array(0, 1, sizeof( Block )) , .tetros_cache =  new_array(0, 1, sizeof( Block )) , .tetro_idx =  0 , .rotation_idx =  0 , .font_loaded =  0 } , sizeof(Game)) ;
      ~~~~                                                                                                                                                                                                                       ^~~~
...\v\examples\tetris:3:43: warning: incompatible pointer types passing 'wchar_t **' (aka 'unsigned short **') to parameter of type 'byteptr *' (aka 'unsigned char **') [-Wincompatible-pointer-types]
   os__args = os__init_os_args_wide(argc, argv);
                                          ^~~~
...\v\vlib\os\os_windows.v:77:57: note: passing argument to parameter 'argv' here
 array_string os__init_os_args_wide (int argc, byteptr* argv) {
                                                        ^
23 warnings generated.
lld: error: lld doesn't support linking directly against ...\v\thirdparty\glfw\glfw3.dll, use an import library
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose

The previous issue I created regarding this was closed prematurely.

vitalyster commented 4 years ago

You need to have libglfw3.a to link examples correctly. However, binary glfw distribution for Windows provide this file for msvc and MinGW-W64(msvcrt.dll) and this will not be suitable for llvm-mingw (ucrt.dll) compiler. You need to build glfw from source (just cmake . -D "MinGW Makefiles" && mingw32-make from the same llvm-mingw environment will create suitable libglfw3.a)

cliserkad commented 4 years ago

I use the MSVC compiler through the build tools that came with Visual Studio to compile things like that. I had to build glad.c with the "x64 native build tools" command prompt which took me a while to figure out.