Thread: how to compile C++ file on linux OS

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    2

    how to compile C++ file on linux OS

    Hi All ,

    I am very much new for this forum as well as Linux operating system.
    I am facing a silly problem . I am making a small C++ project on rad hat Linux.

    I create a " Application" directory in witch i make a application.h which contain some .h files and a class declaration . Appliction.cpp file contains application.h file and class defination and main function . As i compile the application.cpp by using g++ -o a.out application.cpp then it gives the bundle of errors.


    While if i just create a cpp file and compile it ,it works fine.

    My question is , is there any different way to create .h file in Linux

    all suggestion are appriciated.

    Thanks in advance

    ND

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Here's a clue - tell us the error messages
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    2
    i am using diskIO.cpp
    after compilation it gives these massages




    [root@localhost diskIO]# g++ diskIO.cpp -o t.out


    In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
    from /usr/include/c++/3.2.2/backward/disk.h:5,
    from diskIO.cpp:1:
    /usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
    diskIO.cpp:3: syntax error before `::' token
    diskIO.cpp:7: ISO C++ forbids declaration of `memset' with no type
    diskIO.cpp:7: `int memset' redeclared as different kind of symbol
    /usr/include/string.h:58: previous declaration of `void* memset(void*, int,
    unsigned int)'
    diskIO.cpp:7: initializer list being treated as compound expression
    diskIO.cpp:9: parse error before `for'
    diskIO.cpp:9: parse error before `;' token
    diskIO.cpp:9: syntax error before `++' token
    diskIO.cpp:12: `hdd_no' was not declared in this scope
    diskIO.cpp:12: ISO C++ forbids declaration of `sprintf' with no type
    diskIO.cpp:12: `int sprintf' redeclared as different kind of symbol
    /usr/include/stdio.h:303: previous declaration of `int sprintf(char*, const
    char*, ...)'
    diskIO.cpp:12: initializer list being treated as compound expression
    diskIO.cpp:13: ISO C++ forbids declaration of `fin' with no type
    diskIO.cpp:13: invalid conversion from `FILE*' to `int'
    diskIO.cpp:14: parse error before `if'
    diskIO.cpp:17: ISO C++ forbids declaration of `tt' with no type
    diskIO.cpp:18: parse error before `}' token
    diskIO.cpp: In function `int main()':
    diskIO.cpp:32: `linux_diskIO' undeclared (first use this function)
    diskIO.cpp:32: (Each undeclared identifier is reported only once for each
    function it appears in.)
    diskIO.cpp:32: parse error before `;' token
    diskIO.cpp:33: `di' undeclared (first use this function)

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You're probably using
    #include <iostream.h>
    where g++ expects the more modern standard
    #include <iostream>

    Along with that, you might not be using namespaces (correctly), also a more modern feature of C++.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Your code looks to be a horrible mix of C and C++ from some of those messages

    I can't tell much more without seeing some code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. Linux OS to Windows OS code
    By sw9830 in forum C Programming
    Replies: 2
    Last Post: 02-28-2003, 03:11 PM