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

[mingw64] [mpv.com] [clang] No console output #1794

Closed
Ajaja opened this issue Aug 21, 2020 · 11 comments
Closed

[mingw64] [mpv.com] [clang] No console output #1794

Ajaja opened this issue Aug 21, 2020 · 11 comments

Comments

@Ajaja
Copy link
Contributor

Ajaja commented Aug 21, 2020

Built with clang mpv.com does not show console output. It behaves the same way as mpv.exe.

@1480c1
Copy link
Member

1480c1 commented Sep 9, 2020

Hmm

gcc

PS D:\mabs> file .\local64\bin-video\mpv.com
.\local64\bin-video\mpv.com: PE32+ executable (console) x86-64 (stripped to external PDB), for MS Windows
PS D:\mabs> file .\local64\bin-video\mpv.exe
.\local64\bin-video\mpv.exe: PE32+ executable (GUI) x86-64 (stripped to external PDB), for MS Windows

clang

PS D:\> file $(Get-Command mpv.com).Source
D:\media-autobuild_suite\local64\bin-video\mpv.com: PE32+ executable (GUI) x86-64 (stripped to external PDB), for MS Windows
PS D:\> file $(Get-Command mpv).Source
D:\media-autobuild_suite\local64\bin-video\mpv.com: PE32+ executable (GUI) x86-64 (stripped to external PDB), for MS Windows

@Ajaja
Copy link
Contributor Author

Ajaja commented Sep 10, 2020

mpv.com builds here:
https://github.com/mpv-player/mpv/blob/478d39c57492107ce8d5a33e80d5624db330ceab/wscript_build.py#L622

I think the problem is:

$ clang -o mpv.com  -mwindows  -municode -mconsole win32-console-wrapper.c
clang: warning: argument unused during compilation: '-mconsole' [-Wunused-command-line-argument]

GCC gives priority to -mconsole and ignores -mwindows

@1480c1
Copy link
Member

1480c1 commented Sep 10, 2020

Interestingly, I can't tell where the mwindows comes from, but for mpv.com, it should have used mconsole instead

@1480c1
Copy link
Member

1480c1 commented Sep 10, 2020

@wiiaboo
Copy link
Member

wiiaboo commented Sep 10, 2020

What happens if you remove -mwindows from there? Does it then use -mconsole as expected? The latter is only supposed to be used in the wrapper, not in the main executable.

@wiiaboo
Copy link
Member

wiiaboo commented Sep 10, 2020

And why does GCC prefer -mconsole to -mwindows if both are used? Or does -mconsole being used after overrides -mwindows? If so, why doesn't clang do the same?

@wiiaboo
Copy link
Member

wiiaboo commented Sep 10, 2020

Actually, they're supposed to not be exclusive:

On the other hand, you can use both -mconsole and -mwindows when you build your app. They are not mutually exclusive.
gcc -mconsole -mwindows main.c
This produces an application that targets the console subsystem. And you get the standard -mwindows set of Win32 libraries automatically linked. It's probably the simplest way to achieve your goal.

@Ajaja how about if you replace -mconsole by -Wl,--subsystem,console?

@Ajaja
Copy link
Contributor Author

Ajaja commented Sep 10, 2020

It's easy to check

$ clang -o mpv.com  -mwindows  -municode -mconsole win32-console-wrapper.c
clang: warning: argument unused during compilation: '-mconsole' [-Wunused-command-line-argument]
$ file mpv.com
mpv.com: PE32+ executable (GUI) x86-64, for MS Windows

$ clang -o mpv.com -municode -mconsole -mwindows win32-console-wrapper.c
clang: warning: argument unused during compilation: '-mconsole' [-Wunused-command-line-argument]
$ file mpv.com
mpv.com: PE32+ executable (GUI) x86-64, for MS Windows

$ gcc -o mpv.com  -mwindows  -municode -mconsole win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

$ gcc -o mpv.com -municode -mconsole -mwindows win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

$ clang -o mpv.com -municode -Wl,--subsystem,console -mwindows win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

$ clang -o mpv.com  -mwindows  -municode -Wl,--subsystem,console win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

$ gcc -o mpv.com  -mwindows  -municode -Wl,--subsystem,console win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

$ gcc -o mpv.com -municode -Wl,--subsystem,console -mwindows win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

So, looks like -Wl,--subsystem,console works.

@wiiaboo
Copy link
Member

wiiaboo commented Sep 10, 2020 via email

@Ajaja
Copy link
Contributor Author

Ajaja commented Sep 10, 2020

@wiiaboo
It's OK

$ gcc -o mpv.com  -mwindows  -municode -Wl,--subsystem,console win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

$ gcc -o mpv.com -municode -Wl,--subsystem,console -mwindows win32-console-wrapper.c
$ file mpv.com
mpv.com: PE32+ executable (console) x86-64, for MS Windows

@1480c1
Copy link
Member

1480c1 commented Sep 10, 2020

mpv-player/mpv#8073

jeeb pushed a commit to mpv-player/mpv that referenced this issue Oct 14, 2020
Fixes an issue with clang not using the -mconsole option if mwindows
is present resulting in mpv.com being a gui program instead of a
console program.

Does not interfere with gcc compilation.

result without this patch

```
file .\mpv.com .\mpv.exe
.\mpv.com: PE32+ executable (GUI) x86-64 (stripped to external PDB)
.\mpv.exe: PE32+ executable (GUI) x86-64 (stripped to external PDB)
```

both executables open the mpv gui with out console output.

result with this patch

```
file .\mpv.com .\mpv.exe
.\mpv.com: PE32+ executable (console) x86-64 (stripped to external PDB)
.\mpv.exe: PE32+ executable (GUI) x86-64 (stripped to external PDB)
```

mpv.com properly outputs text to console instead of instantly opening
a gui

`, for MS Windows` removed from the end of file outputs to reduce col
count

m-ab-s/media-autobuild_suite#1794

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
Dudemanguy pushed a commit to Dudemanguy/mpv that referenced this issue May 18, 2021
Fixes an issue with clang not using the -mconsole option if mwindows
is present resulting in mpv.com being a gui program instead of a
console program.

Does not interfere with gcc compilation.

result without this patch

```
file .\mpv.com .\mpv.exe
.\mpv.com: PE32+ executable (GUI) x86-64 (stripped to external PDB)
.\mpv.exe: PE32+ executable (GUI) x86-64 (stripped to external PDB)
```

both executables open the mpv gui with out console output.

result with this patch

```
file .\mpv.com .\mpv.exe
.\mpv.com: PE32+ executable (console) x86-64 (stripped to external PDB)
.\mpv.exe: PE32+ executable (GUI) x86-64 (stripped to external PDB)
```

mpv.com properly outputs text to console instead of instantly opening
a gui

`, for MS Windows` removed from the end of file outputs to reduce col
count

m-ab-s/media-autobuild_suite#1794

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants