Files
2025-11-21 17:17:42 +01:00

3.9 KiB

  • MSVC Compiler Options
/nologo - Suppresses display of the copyright banner when the compiler starts up.
/Ox - Code optimization - a subset of /O2 option (creates fast code) that doesn't include /GF (string pooling) or /Gy (function-level linking).
/MT - Compiles to a multithreaded executable file, by using LIBCMT.lib (statically linking C runtime library).
/W0 - Suppresses all warnings.
/GS- - Disables buffer security.
/D<string> - Defines a <string> constant (equivalent to #define directive at the beginning of a source code file). Helpful for enabling/disabling parts of the code during development and switching into a production phase.
/Tc - Specifies a C source file. All code is treated as C code (instead of C++).
/link - Passes the specified options to the linker.
/OUT - Specifies the output file name.
/SUBSYSTEM - Tells the operating system how to run the .exe file, ex. CONSOLE (console app), WINDOWS (GUI app), etc.
/MACHINE - Specifies the target platform, ex. x86, x64, ARM, etc.
/DLL - Builds a DLL.
  • Compile windows assembly with nasm
    • nasm -f "format" "code.asm" -o output_file.format
    • nasm -f bin eternalblue_kshellcode_x64.asm -o ./sc_x64_kernel.bin
  • Compile as windows exe with ming
    • % compile 64bit windows code
      • x86_64-w64-mingw32- ("tab,tab,tab", to view all installed compilers")
    • % compile 32bit windows code
      • i686-w64-mingw32- ("tab,tab,tab", to view all installed compilers")
    • % examples of compiling C/C++ code on linux for windows
      • x86_64-w64-mingw32-gcc hello_world.c -o hi.exe
      • x86_64-w64-mingw32-g++ hello_world.pp -o hi.exe
  • Compile with mono
    • % compiling cs (C-Sharp) code into a static.exe file
      • mono-csc compile_me.cs
    • % compile with mcs ("for versions of mono-devel that doesn't come with csc")
      • dmcs compile_me.cs ("old-not-supported-verion")
      • mcs compile_me.cs
    • Run/test compiled EXE with mono-devel
      • mono runme.exe
  • Compile Visual Studio projects on Linux
    • Installing .NET

      • sudo snap search dotnet
      • sudo snap install <package_name>
      • for some applications you may have to install ("COMPLETE .NET") vs .Net Core with snap
    • Create new project

      • dotnet new console
    • Create solution project

      • cd ./path/to/vs/project
      • dotnet new <option>
      • dotnet new sln
    • Create new project file

      • get list of project types
        • dotnet new project
    • Create new project file - dotnet new <project_file_type> - dotnet new mstest

    • list, add, or remove project files from the the solution.sln file

      • double check if the soultion file has your project in it
        • dotnet sln list
      • add a project file to your solution file in the current dir
        • dotnet sln add project.csproj
      • remove project file from the solution file in the current dir
        • dotnet sln remove project.csproj
    • how to build a probject

      • dotnet build
      • dotnet msbuild
      • NOTE; ("this may only complie C# code into valid DLLs NOT EXEs")
      • build/msbuild with the system ARCH
        • dotnet build -r win-x64 project.csproj
      • how to run a project without testing with a final binary
        • dotnet run
      • true method to compile projects into .exe binaries
        • compile linux binary
          • dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained false
        • compile windows.exe binary
          • dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained false
    • adding the missing reference/packages you forget with dotnet+nuget

      • % https://www.nuget.org/ -> "search for reference/package
      • dotnet add package <package-content-whatever-string>
      • cd /path/to/current/project
      • dotnet add package System.ServiceProcess.ServiceController --version 6.0.0-preview.5.21301.5
  • compiling for real with xbuild and the solution file
    • NOTE; (xbuild is for stuff that is <Full .NET>, not just <.dot Core>)
    • xbuild solution_file.sln
    • NOTE: xbuild no longer supported