MINGW-packages icon indicating copy to clipboard operation
MINGW-packages copied to clipboard

Gcc got incorrect file name when building exe

Open goshut opened this issue 1 year ago • 4 comments

Description / Steps to reproduce the issue

import os
import sys
import subprocess
import logging
import time

filename = r"D:\test\c++test\VC_c++_test\example\涓枃.c"
filename_base, extension = os.path.splitext(filename)
compiler = "D:\\tool\\gcc_huanjing\\msys64\\ucrt64\\bin\\gcc.exe"
subprocess.Popen(
    [
        compiler,
        "-fexec-charset=gbk",
        "-fdiagnostics-color=always",
        "-g",
        filename,
        "-o",
        filename_base + ".exe",
    ],
)
# time.sleep(3)

I received an exe with an incorrect file name "脰脨脦脛.exe" after running the above script. It should be like this "涓枃.exe" If I ask scripts to pause for a while,It will generate the correct file name again.

My operating system is using GBK encoding.

Expected behavior

The generated exe file has been changed to the wrong name

Actual behavior

I conducted a small experiment and created an empty file called "涓枃. exe" in my folder, then ran the task

An interesting thing happened, my empty file became a runnable exe program with incorrect names

So I figured out the whole process : run tasks first created the exe program correctly, so it overwritten my empty file with the same name, and then a program gave it an ugly name馃槄馃槄

Verification

  • [X] I have verified that my MSYS2 is up-to-date before submitting the report (see https://www.msys2.org/docs/updating/)

Windows Version

Windows_NT x64 10.0.22621

MINGW environments affected

  • [X] MINGW64
  • [ ] MINGW32
  • [ ] UCRT64
  • [ ] CLANG64
  • [ ] CLANG32
  • [ ] CLANGARM64

Are you willing to submit a PR?

No response

goshut avatar Jan 30 '24 16:01 goshut

How can I turn off this renaming function or let it work normally?

goshut avatar Jan 30 '24 17:01 goshut

does gcc.exe in your $PATH? if yes, then maybe just do compiler = "gcc.exe"

raedrizqie avatar Jan 30 '24 17:01 raedrizqie

I tried, but it still couldn't. new py

import os
import sys
import subprocess
import logging
import time

filename = r"D:\test\c++test\VC_c++_test\涓枃.c"
filename_base, extension = os.path.splitext(filename)
compiler = "gcc.exe"
subprocess.Popen(
    [
        compiler,
        "-fexec-charset=gbk",
        "-fdiagnostics-color=always",
        "-g",
        filename,
        "-o",
        filename_base + ".exe",
    ],
)
# time.sleep(3)

I think the execution logic of this renaming function is to determine whether the output encoding of its parent process is consistent with itself (UTF8 in Python). If it is inconsistent (GBK in the system), rename it

But it overlooks one point, which is that if the compiler executes a task and its parent process is already closed, it will search for the parent process or the system's default encoding. This results in it not being able to truly obtain encoding information

goshut avatar Jan 31 '24 12:01 goshut

try something like this maybe?

filename = r"D:\test\c++test\VC_c++_test\example\中文.c".encode(encoding="utf-8")

raedrizqie avatar Jan 31 '24 12:01 raedrizqie