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?

void run(string FileName, string Parameters="")
{
    SHELLEXECUTEINFO ShExecInfo;
    ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    ShExecInfo.hwnd = NULL;
    ShExecInfo.lpVerb = "open";
    ShExecInfo.lpFile = FileName.c_str();
    ShExecInfo.lpParameters = Parameters.c_str();
    ShExecInfo.lpDirectory = NULL;
    ShExecInfo.nShow = SW_SHOWNORMAL;
    ShExecInfo.hInstApp = NULL;

    ShellExecuteEx(&ShExecInfo);

    if(ShExecInfo.hProcess)
    CloseHandle(ShExecInfo.hProcess);
}

after several tries i found the problem: when we use some API functions, we must add the libraries too, or we have errors without notice.

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,"-Wall -g -std=c++14  -c \"C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.cpp\" -o \"C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.o\"");
    run(FileName1,"-o C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.exe C:\\Users\\Cambalinho\\Documents\\CB\\testfolder\\bin\\Debug\\test2.o -static-libstdc++ -static-libgcc -fpermissive \"C:\\Program Files\\mingw-w64\\x86_64-7.2.0-win32-seh-rt_v5-rev1\\mingw64\\x86_64-w64-mingw32\\lib\\libgdi32.a\"");

now i can create an exe that executes without dll's dependencies.
thank so much for all

now i'm testing these code on Untitled1.h:

#include <iostream>
#include <fstream>
#include <windows.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <tchar.h>
#include <algorithm>
#include <ctype.h>
#include <iterator>
#include <typeinfo>
#include <sstream>
#include <conio.h>
#define BaseClass :
#define Exit_Procedure return
#define StringNotFound string::npos
#define Add push_back

typedef int integer;
typedef bool Boolean;
typedef void procedure;
using namespace std;

struct size
{
    int Width;
    int Height;
};

using namespace std;

class console
{
public:
    HWND ConsoleWindow;
    HANDLE ConsoleHandle;
    HDC ConsoleHDC;

    operator HWND()
    {
        return ConsoleWindow;
    }

    operator HANDLE()
    {
        return ConsoleHandle;
    }

    operator HDC()
    {
        return ConsoleHDC;
    }

    console()
    {
        ConsoleWindow = GetConsoleWindow();
        ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
        ConsoleHDC = GetWindowDC(ConsoleWindow);
    }

    void write()
    {
        //nothing
    }

    template<typename first_t, typename... rest_t>
    void write(const first_t &first, const rest_t... rest)
    {
        std::cout << first;

        write(rest...); //function is recursive
                        //when the parameter pack becomes empty
                        //write(); will be called with no parameters
                        //which is why we declare it above
    }

    void read()
    {
        //wait if the eneter key is pressed:
        cin.ignore();
        cin.get();
    }

    template<typename first_t, typename... rest_t>
    void read(first_t &first, rest_t... rest)
    {
        std::cin >> first;
        read(rest...); //function is recursive
                        //when the parameter pack becomes empty
                        //read(); will be called with no parameters
                        //which is why we declare it above
    }

    void read(string &parameter)
    {
        std::getline (std::cin,parameter);
    }

    void read(char *parameter)
    {
        cin.getline (parameter, 256);
    }

    size GetWindowSize()
    {
        PCONSOLE_SCREEN_BUFFER_INFOEX consolesize;
        consolesize->cbSize=sizeof(PCONSOLE_SCREEN_BUFFER_INFOEX);
        GetConsoleScreenBufferInfoEx(ConsoleHandle,consolesize);
        return {(int )(consolesize->srWindow.Right + consolesize->srWindow.Left), (int)(consolesize->srWindow.Bottom + consolesize->srWindow.Top)};
    }

    void SetWindowSize(size newsize)//newaize recive the number of characters been showed on window
    {
        CONSOLE_SCREEN_BUFFER_INFOEX consolesize;

        consolesize.cbSize=sizeof(consolesize);
        GetConsoleScreenBufferInfoEx(ConsoleHandle,&consolesize);

        COORD c;
        c.X = newsize.Width;
        c.Y = newsize.Height;
        consolesize.dwSize = c;
        consolesize.dwMaximumWindowSize = c; //change the window max size

        consolesize.srWindow.Left = 0;
        consolesize.srWindow.Right = c.X;
        consolesize.srWindow.Top = 0;
        consolesize.srWindow.Bottom = c.Y;
        //srWindow, c and dwMaximumWindowSize are the same
        //here i don't use pixels. for that i must get the current font size and then calculate the number of characters

        SetConsoleScreenBufferInfoEx(ConsoleHandle, &consolesize);
        SetConsoleWindowInfo(ConsoleHandle, FALSE, &consolesize.srWindow);
    }

    void SetViewSize(size Size)
    {
        COORD coord;
        coord.X = Size.Width;
        coord.Y = Size.Height;

        _SMALL_RECT Rect;
        Rect.Top = 0;
        Rect.Left = 0;
        Rect.Bottom = Size.Width-1;
        Rect.Right = Size.Height-1;

        SetConsoleScreenBufferSize(ConsoleHandle, coord);
        SetConsoleWindowInfo(ConsoleHandle, TRUE, &Rect);
    }

    string GetWindowTitle()
    {
        TCHAR szOldTitle[MAX_PATH];
        GetConsoleTitle(szOldTitle,MAX_PATH);
        return string(szOldTitle);
    }

    void SetWindowTitle(string title)
    {
        SetConsoleTitle(title.c_str());
    }

    COORD GetCarretPosition()
    {
        CONSOLE_SCREEN_BUFFER_INFOEX carretpos;
        carretpos.cbSize=sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
        GetConsoleScreenBufferInfoEx(ConsoleHandle,&carretpos);
        COORD pos=carretpos.dwCursorPosition;
        return pos;
    }

    void SetCarretPosition(COORD Pos)
    {
        SetConsoleCursorPosition(ConsoleHandle,Pos);
    }

    WORD GetCarretColor()
    {
        CONSOLE_SCREEN_BUFFER_INFO screen;
        GetConsoleScreenBufferInfo(ConsoleHandle, &screen);
        return screen.wAttributes;
    }

    void SetCarretColor(WORD CarretColor)
    {
        SetConsoleTextAttribute(ConsoleHandle,CarretColor);
    }

    void clear(WORD Atribute=FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE)
    {
        COORD topLeft  = { 0, 0 };
        DWORD written;
        CONSOLE_SCREEN_BUFFER_INFO screen;
        GetConsoleScreenBufferInfo(ConsoleHandle, &screen);
        FillConsoleOutputCharacterA(
            ConsoleHandle, ' ', screen.dwSize.X * screen.dwSize.Y, topLeft, &written
        );
        FillConsoleOutputAttribute(
            ConsoleHandle, Atribute,
            screen.dwSize.X * screen.dwSize.Y, topLeft, &written
        );
        SetConsoleCursorPosition(ConsoleHandle, topLeft);
    }

}Console,*PConsole;

bool dirExists(const std::string& dirName_in)
{
    DWORD attribs = ::GetFileAttributesA(dirName_in.c_str());
    if (attribs == INVALID_FILE_ATTRIBUTES)
    {
        return false;
    }
    return (attribs & FILE_ATTRIBUTE_DIRECTORY);
}

char* ConvertToUpperCase(const char *s)
{
    char *newstr= (char*)malloc(strlen(s) + 1);
    size_t i = 0;
    for ( ; s[i]; i++)
        newstr[i] = toupper(s[i]);
    newstr[i] = '\0';
    return newstr;
}

bool IfFolderExist(const char *szPath)
{
  DWORD dwAttrib = GetFileAttributes(szPath);

  return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
         (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}

string FindDirectory(std::string FindDirectoryName[2], std::string StartDirectory="C:")
{
    WIN32_FIND_DATA file={0};
    string str=StartDirectory+ "\\*";
    HANDLE search_handle = FindFirstFile(str.c_str(), &file);
    static bool blnFindDirectoryName=false;
    static string strFolderName ="";

    //testing if the folder is valid:
    if (search_handle != INVALID_HANDLE_VALUE)
    {
        do
        {
            //if the folder was founded, then break the loop:
            if(strFolderName!="")
                break;

            //for avoid files names and the folders "." and "..":
            if ((file.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && strcmp(file.cFileName, "..") && strcmp(file.cFileName, "."))
            {
                //cout <<StartDirectory + "\\" + file.cFileName << endl;

                //testing if the folder was found
                //and add it on static strFolderName
                if(string(file.cFileName)==FindDirectoryName[0] && blnFindDirectoryName==false)
                {
                    if(FindDirectoryName[1]=="")
                    {
                        strFolderName = StartDirectory+ "\\" + file.cFileName;
                        break;
                    }
                    else
                        blnFindDirectoryName=true;
                }
                if(string(file.cFileName)==FindDirectoryName[1] && blnFindDirectoryName==true)
                {
                    //MessageBox(NULL, string(StartDirectory+ "\\" + file.cFileName).c_str(), "found it", MB_OK);
                    strFolderName = StartDirectory+ "\\" + file.cFileName;
                    break;
                }
                else
                {
                    //or continue searching:
                    FindDirectory(FindDirectoryName,StartDirectory + "\\" + file.cFileName);
                }
            }
        } while (FindNextFile(search_handle, &file) && search_handle!=NULL);
        //destroy the search_handle:
        FindClose(search_handle);
    }
    //return the search folder full path:
    return strFolderName;
}

//test if the char is a delimiter:
bool IsDelimiter(char chr, const string& chrDelimiters)
{
    for(char itr : chrDelimiters)
    {
        if(chr == itr)
            return true;
    }
    return false;
}

template<typename T>
string operator+(string strText, int strText2)
{
    stringstream  strError;
    strError << strText << strText;
    return (strError.str());
}

bool find(string Text, string StringToSearch)
{
    if(Text.find(StringToSearch) != std::string::npos)
        return true;
    else
        return false;
}

HANDLE mutex;
void Main(vector<string> argumentlist, bool IsOpened);

int main (int argc, char **argv)
{
    //Arguments list:
    vector<string> test;
    for (int i=0; i<argc;i++)
    {
        test.push_back(argv[i]);
    }

    //Testing if the application is executing:
    mutex = CreateMutex( NULL, TRUE, "MyApp" );

    if ( mutex!=NULL)
    {
        Main(test,true);
    }
    else
    {
        Main(test, false);
    }
    if(mutex)
        CloseHandle(mutex);
    return 0;
}

    void write()
    {
        //nothing
    }

    template<typename first_t, typename... rest_t>
    void write(const first_t &first, const rest_t... rest)
    {
        std::cout << first;

        write(rest...); //function is recursive
                        //when the parameter pack becomes empty
                        //write(); will be called with no parameters
                        //which is why we declare it above
    }

    void read()
    {
        //wait a enter key pressed:
        cin.get();
    }

    template<typename first_t, typename... rest_t>
    void read(first_t &first, rest_t... rest)
    {
        std::cin >> first;
        read(rest...); //function is recursive
                        //when the parameter pack becomes empty
                        //read(); will be called with no parameters
                        //which is why we declare it above
    }

    void read(string &parameter)
    {
        std::getline (std::cin,parameter);
    }

    void read(char *parameter)
    {
        cin.getline (parameter, 256);
    }

and now the cpp file:

#include "Untitled1.h"
void Main (vector < string > argumentlist , boolean IsOpened ) 
{
    integer a =  20;

    a = a + 30 ;
    write ( a ) ;
    write ( "hello world" ) ;
}

the Code Blocks can compile it.
but if i use Command Prompth\CMD, i will get an object file and these errors:

C:\Program Files\mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin>x86_64-w64-mingw32-g++.exe
-o "C:\Users\Cambalinho\Documents\CB\testfolder\bin\Debug\test2.exe" "C:\Users\Cambalinho\Documents\
CB\testfolder\bin\Debug\test2.o" -static-libstdc++ -static-libgcc -fpermissive "C:\Program Files\min
gw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\x86_64-w64-mingw32\lib\libgdi32.a"

C:\Users\Cambalinho\Documents\CB\testfolder\bin\Debug\test2.o: In function `main':
C:/Users/Cambalinho/Documents/CB/testfolder/bin/Debug/Untitled1.h:335: undefined reference to `Main(
std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::al
locator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool)'
C:/Users/Cambalinho/Documents/CB/testfolder/bin/Debug/Untitled1.h:339: undefined reference to `Main(
std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::al
locator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool)'
collect2.exe: error: ld returned 1 exit status

i don't understand why these errors... can anyone advice me?

I'm ignoring the code dumps. I'll share how I research how to command line compile using a Google search.

  1. https://www.google.com/search?client=firefox-b-1-ab&q=compiling+from+the+command+line+%22Code+Blocks%22
  2. That's pretty close. I think this link is the one you want: http://forums.codeblocks.org/index.php?topic=11897.0

It appears this and other issues pop up when you try to move to the command line. (In ref to %Program Files or such.)

hey i know the command line.
i can create the exe with standard code:

#include <iostream>

int main()
{
   std::cout << "hello world\n";
   std::cin.get();
   return 0;
}

yes.. i have tested and the exe is created..
but if i use my own header file, i get that several errors.
but if i compile the same code, using the Code Blocks, the exe is created...i don't know if Code Blocks is using more commands that show on 'Build Log' view.

"if I use my own..."

This means you either shouldn't do that or dive into how yours differs from the working version.

i never thot that.. on Command Prompt(CMD.exe) the errors was showed...
i nevert thot that i was doing 1 error between uppercases :(
"C:\Users\Cambalinho\Documents\CB\testfolder\bin\Debug\test2.o: In function main': C:/Users/Cambalinho/Documents/CB/testfolder/bin/Debug/Untitled1.h:335: undefined reference toMain(
std::vector<std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::al
locator<std::
cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool)'
C:/Users/Cambalinho/Documents/CB/testfolder/bin/Debug/Untitled1.h:339: undefined reference to `Main(
std::vector<std::cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::al
locator<std::
cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, bool)'
collect2.exe: error: ld returned 1 exit status"
yes i get more help to find the real problem.
anotherthing: these string is saved on File:

"write(\"hello world\n\")",

the '\n' will give us a new line on file... for resolve the problem we must add the double slash:

"write(\"hello world\\n\")",

thank you so much for all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.