GNU compiler: how can i compiler using command lines?

i'm trying using the GNU compiler with command lines( using the ShellExecuteEx()).
when i do:

string FileName1="C:\\Program Files\\mingw-w64\\x86_64-7.2.0-win32-seh-rt_v5-rev1\\mingw64\\bin\\x86_64-w64-mingw32-g++.exe";
    run(FileName1,"-c \"C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.cpp\"");

the object file is created.
these line creates the exe:

run(FileName1,"-o C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.exe C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.o");

(tested)
but the exe have some dependencies...
so seen the Code Blocks:

x86_64-w64-mingw32-g++.exe -Wall -g -std=c++14  -c C:\Users\Cambalinho\Documents\CB\testfolder\main.cpp -o obj\Debug\main.o
x86_64-w64-mingw32-g++.exe -L"C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Lib\x86" -o bin\Debug\testfolder.exe obj\Debug\main.o  -static-libstdc++ -static-libgcc -fpermissive  "..\..\..\..\..\Program Files\mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\x86_64-w64-mingw32\lib\libgdi32.a"
Output file is bin\Debug\testfolder.exe with size 2.92 MB
Process terminated with status 0 (0 minute(s), 8 second(s))
0 error(s), 0 warning(s) (0 minute(s), 8 second(s))

the "-static-libstdc++ -static-libgcc" adds the exe dependencies.... but i can't add it correctly.. the exe isn't created :(
can anyone advice me?