Author Topic: how to compile c++ programm  (Read 5871 times)

Offline ric63

  • Single posting newcomer
  • *
  • Posts: 2
how to compile c++ programm
« on: January 15, 2012, 11:14:25 am »
Hi,
I am an beginner to c++. I installed Code::Block under Ubuntu and I writted a simple program that work.
I now would make a library for Ubuntu.
When I make a new project -> static library, I see a .c file and not .cpp file.
Why ?

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: how to compile c++ programm
« Reply #1 on: January 15, 2012, 06:27:00 pm »
All C code is valid C++ code; you could rename the file extension (it probably will need to be re-added to your project).
Alternatively, you could delete the C file and add however many C++ files you want.  The structure of code in a static library is not nearly as strict as in other areas because it is simply a collection of object files waiting to be linked at a later point in time.

You do have a valid point though; for continuity, the static library wizard should have a language selection page...
« Last Edit: January 15, 2012, 09:49:01 pm by Alpha »

Offline ric63

  • Single posting newcomer
  • *
  • Posts: 2
Re: how to compile c++ programm
« Reply #2 on: January 15, 2012, 07:25:47 pm »
thanks.
it work
I have deleted the .c file and added .cpp file.
So, I have builded the static library.
bye

zabzonk

  • Guest
Re: how to compile c++ programm
« Reply #3 on: January 15, 2012, 07:44:44 pm »
Quote
All C code is valid C++ code

This is very, very far from true.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: how to compile c++ programm
« Reply #4 on: January 15, 2012, 08:35:18 pm »
Quote
All C code is valid C++ code

This is very, very far from true.
Example/link??

zabzonk

  • Guest
Re: how to compile c++ programm
« Reply #5 on: January 15, 2012, 08:49:25 pm »
Well, a couple of simple examples:

Code
// valid C code not valid C++
int main() {
     int new = 0;
     char * p = (void *) 0;
}

But there are  a lot more.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7789
    • My Best Post
Re: how to compile c++ programm
« Reply #6 on: January 15, 2012, 09:05:08 pm »
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: how to compile c++ programm
« Reply #7 on: January 15, 2012, 09:48:13 pm »
Thanks.

I should have expected I would miss something obvious, having learned to program by means of Google and reading source (like Code::Blocks!) in my free time over the past year and a bit.  (But you may already have guessed at my inexperience if you looked at my style in the patches I have submitted.)

I still have much to learn...
« Last Edit: January 15, 2012, 09:50:21 pm by Alpha »