Author Topic: how to compile c++ program  (Read 39877 times)

tb001

  • Guest
how to compile c++ program
« 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??

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
how to compile c++ program
« Reply #1 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.
Be patient!
This bug will be fixed soon...

Anonymous

  • Guest
how to compile c++ program
« Reply #2 on: November 02, 2004, 01:12:22 am »
Thanks, it's working.

Offline Fatman

  • Multiple posting newcomer
  • *
  • Posts: 11
    • https://dreamtrack.dnsalias.com/
No DLL projects?
« Reply #3 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.

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
how to compile c++ program
« Reply #4 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: [Select]

#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.
Be patient!
This bug will be fixed soon...

Offline Fatman

  • Multiple posting newcomer
  • *
  • Posts: 11
    • https://dreamtrack.dnsalias.com/
how to compile c++ program
« Reply #5 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...

rocky26

  • Guest
Re: how to compile c++ program
« Reply #6 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? 

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6984
    • My Best Post
Re: how to compile c++ program
« Reply #7 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

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_%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

Tim S.
 
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org