compiler dependency of a code

Hi,
i have a cpp code which is showing no error if I compile it by the command icc.
But if I compile it by g++, it is showing errors.
I am just confused about this pattern.
If anyone have any idea, please suggest.
I guess it would be slightly easier to help you if you posted your code and the errors you get...
yeah both are different compiler. Some of the code will work properly on CC( windows compiler) and the same code will throw compile error in linux.

Main reason being that in the code we might be calling some functions which are specific to windows and the linux might not understand.U can take the example of threading ,if you are using WIN32 threads then it won work on linux, u have to use posix.
closed account (1yR4jE8b)
that could be one reason, the other reason might be is that his code might be non-standard, and a certain compiler may accept it (this is bad) and the other compiler would pick it up and throw an error (this is good).

So it could be one of many reasons, which is why you should post your code and/or the compiler errors you are getting..

and before you post a wall of code....make sure it's in code tags at least.
Thanks for the suggestions. I am working in Linux only. Actually the code is huge with many subprograms used in it, that is why its not easy to post it here. But I can give you the details of the main error which is as follows:
Suppose I have a subprogram namely "sub.h" and there is a function used in this named as "void fun()".
Now if I want to use the function "fun()" in the main program, I just did it as following

#include<iostream>
#include "sub.h"
using namespace std;

int main(){
fun();
return(0);
}

you will notice that I have not declared the function "fun()" here, which is an error if I compile it by g++, and it goes fine if I do it by icc.
It is something which bothers me about the reliability of compilers.

closed account (S6k9GNh0)
Compilers have the bad habit of providing the developer with non-standard functions that other compilers feel should be different or not implemented. A great example of this is #pragma once . If your aiming for a flexible project, make sure that your compiler is taking the arguments that enforces strict standards for the language you are using and that abide to them at all costs.
closed account (1yR4jE8b)
is fun() defined in the header or is it compiled seperately?
I think it is more likely that you are using the language incorrectly.

In header files you should, in general, only have function prototypes.
There should be a corresponding source file (like "sub.cpp") that defines the body of the function.

Read here for an example: http://www.cplusplus.com/forum/unices/2313/page1.html#msg8761

Here is another:
1
2
3
4
5
6
7
8
// sub.hpp

#ifndef MYPROJECT_SUB_HPP
#define MYPROJECT_SUB_HPP

void fun();

#endif 
1
2
3
4
5
6
7
8
9
10
11
// sub.cpp

#include <iostream>
using namespace std;

#include "sub.hpp"

void fun()
  {
  cout << "Hello world!\n";
  }
1
2
3
4
5
6
7
8
// main.cpp
#include "sub.hpp"

int main()
  {
  fun();
  return 0;
  }

When you compile, you must, as usual, compile and link both cpp files:

    g++ main.cpp sub.cpp

Hope this helps.
Many Thanks Duoas. This helped me.
Glad to be of help. It is a common confusion. I remember when I was confused by it when I was learning C many, many, many moons ago.
Topic archived. No new replies allowed.