mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
windows: do not link gdi32/shell32 to console applications
* read os.args from argv when we have console * dynamically load CommandLineToArgvW when we are GUI app * link gdi32/shell32 in glfw module
This commit is contained in:

committed by
Alexander Medvednikov

parent
55dbb8b81c
commit
3f0f8bac49
@ -263,6 +263,9 @@ fn (v mut V) cc() {
|
||||
if v.os == .mac {
|
||||
a << '-mmacosx-version-min=10.7'
|
||||
}
|
||||
if v.os == .windows {
|
||||
a << '-municode'
|
||||
}
|
||||
cflags := v.get_os_cflags()
|
||||
// add .o files
|
||||
a << cflags.c_options_only_object_files()
|
||||
|
@ -557,10 +557,42 @@ pub fn (v mut V) generate_main() {
|
||||
}
|
||||
|
||||
pub fn (v mut V) gen_main_start(add_os_args bool) {
|
||||
v.cgen.genln('int main(int argc, char** argv) { ')
|
||||
if (v.os == .windows) {
|
||||
if 'glfw' in v.table.imports {
|
||||
v.cgen.genln('#ifdef V_BOOTSTRAP')
|
||||
v.cgen.genln('int main(int argc, char** argv) { ')
|
||||
v.cgen.genln('#else')
|
||||
// GUI application
|
||||
v.cgen.genln('int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance, LPWSTR cmd_line, int show_cmd) { ')
|
||||
v.cgen.genln(' typedef LPWSTR*(WINAPI *cmd_line_to_argv)(LPCWSTR, int*);')
|
||||
v.cgen.genln(' HMODULE shell32_module = LoadLibrary(L"shell32.dll");')
|
||||
v.cgen.genln(' cmd_line_to_argv CommandLineToArgvW = (cmd_line_to_argv)GetProcAddress(shell32_module, "CommandLineToArgvW");')
|
||||
v.cgen.genln(' int argc;')
|
||||
v.cgen.genln(' wchar_t** argv = CommandLineToArgvW(cmd_line, &argc);')
|
||||
v.cgen.genln(' os__args = os__init_os_args_wide(argc, argv);')
|
||||
v.cgen.genln('#endif')
|
||||
} else {
|
||||
v.cgen.genln('#ifdef V_BOOTSTRAP')
|
||||
v.cgen.genln('int main(int argc, char** argv) { ')
|
||||
v.cgen.genln('#else')
|
||||
// Console application
|
||||
v.cgen.genln('int wmain(int argc, wchar_t* argv[], wchar_t* envp[]) { ')
|
||||
v.cgen.genln('#endif')
|
||||
}
|
||||
} else {
|
||||
v.cgen.genln('int main(int argc, char** argv) { ')
|
||||
}
|
||||
v.cgen.genln(' init();')
|
||||
if add_os_args && 'os' in v.table.imports {
|
||||
v.cgen.genln(' os__args = os__init_os_args(argc, (byteptr*)argv);')
|
||||
if v.os == .windows {
|
||||
v.cgen.genln('#ifdef V_BOOTSTRAP')
|
||||
v.cgen.genln(' os__args = os__init_os_args(argc, (byteptr*)argv);')
|
||||
v.cgen.genln('#else')
|
||||
v.cgen.genln(' os__args = os__init_os_args_wide(argc, argv);')
|
||||
v.cgen.genln('#endif')
|
||||
} else {
|
||||
v.cgen.genln(' os__args = os__init_os_args(argc, (byteptr*)argv);')
|
||||
}
|
||||
}
|
||||
v.generate_hotcode_reloading_main_caller()
|
||||
v.cgen.genln('')
|
||||
|
@ -246,7 +246,7 @@ pub fn (v mut V) cc_msvc() {
|
||||
// Emily:
|
||||
// Not all of these are needed (but the compiler should discard them if they are not used)
|
||||
// these are the defaults used by msbuild and visual studio
|
||||
mut real_libs := ['kernel32.lib', 'user32.lib', 'gdi32.lib', 'winspool.lib', 'comdlg32.lib', 'advapi32.lib', 'shell32.lib', 'ole32.lib', 'oleaut32.lib', 'uuid.lib', 'odbc32.lib', 'odbccp32.lib']
|
||||
mut real_libs := ['kernel32.lib', 'user32.lib', 'advapi32.lib']
|
||||
sflags := v.get_os_cflags().msvc_string_flags()
|
||||
real_libs << sflags.real_libs
|
||||
inc_paths := sflags.inc_paths
|
||||
|
Reference in New Issue
Block a user