Code::Blocks Forums

User forums => Help => Topic started by: tb001 on November 01, 2004, 05:27:20 am

Title: how to compile c++ program
Post by: tb001 on November 01, 2004, 05:27:20 am
Hi,
I am an beginner to c++. I installed mingw and entered some c++ codes in editor. But all the selections in pulldown list under 'Compile' are disabled except 'Select target...'. Did I miss some thing in configuring code::blocks??
Title: how to compile c++ program
Post by: mandrav on November 01, 2004, 11:04:57 am
My guess is you didn't create a project first. Code::Blocks cannot compile a single file (yet).
Click Project/New... and select "console application". This will create a new project containing a single source file named main.cpp.
Hack away then ;)

Yiannis.
Title: how to compile c++ program
Post by: Anonymous on November 02, 2004, 01:12:22 am
Thanks, it's working.
Title: No DLL projects?
Post by: Fatman on January 09, 2005, 01:03:06 am
How do we create a DLL project? I don't see an option for this in Project/New.
Title: how to compile c++ program
Post by: mandrav on January 09, 2005, 01:04:25 pm
There is no DLL template. It was omitted for no good reason  :? .
Anyway, here's some sample code:
Code

#include <windows.h>

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT
#endif

// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
    MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // attach to process
            // return FALSE to fail DLL load
            break;
       
        case DLL_PROCESS_DETACH:
            // detach from process
            break;
       
        case DLL_THREAD_ATTACH:
            // attach to thread
            break;
       
        case DLL_THREAD_DETACH:
            // detach from thread
            break;
    }
    return TRUE; // succesful
}


Create a new empty project and add a source file containing the above code.
Go to project properties and change the "default" target's type to "Dynamic library". Adjust the output filename, if you want.
In the project's build options, add under "Compiler definitions" BUILD_DLL.
If you 're using the VC free toolkit, you will need to add to the project's build options, under the linker options, the two libraries user32.lib and kernel32.lib (you will have to have installed the MS Platform SDK).

HTH,
Yiannis.
Title: how to compile c++ program
Post by: Fatman on January 10, 2005, 01:02:41 am
Thanks Yiannis, that helps. :)

I can use that sample to hack together a set of templates for DLLs, until the devs release a download for "other" project types...
Title: Re: how to compile c++ program
Post by: rocky26 on September 07, 2013, 06:13:08 am
I write a C++ program in empty file and save it. When i'm going to compile it shows some "fatal error: iostream.h: no such file or directory" message? i Dn't  know what is the next step to fix it? 
Title: Re: how to compile c++ program
Post by: stahta01 on September 07, 2013, 06:44:39 am
I write a C++ program in empty file and save it. When i'm going to compile it shows some "fatal error: iostream.h: no such file or directory" message? i Dn't  know what is the next step to fix it? 

Please DO NOT post in threads more than a few years old; it is wrong on most sites.
Some sites do NOT like posting in more than a few weeks old.
Not sure about this site.

Link to FAQs http://wiki.codeblocks.org/index.php?title=FAQ (http://wiki.codeblocks.org/index.php?title=FAQ)

Links to important FAQ for your problem.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)

Please use a new thread for your further posts.
Please read the rules before posting!
http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)

Tim S.