I have tried the commands suggested, to invoke a program that includes a user-defined header, on coliru, but the program doesn't run.
Here are the links:
Header file : defines a couple of math functions:
http://coliru.stacked-crooked.com/a/c5bc0bb639d621db
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#ifndef MY_MATH_H_INCLUDED
#define MY_MATH_H_INCLUDED
int add(int a, int b)
{
return a + b;
}
int multiply(int a, int b)
{
return a * b;
}
#endif // MY_MATH_H_INCLUDED
|
Note:
1) Here, I have included the function definitions also in the header file (rather than just the declarations). That's what I want to do.
2) When I click the "share" button, coliru tries to compile this header and issues an error saying main() function is not found. But it provides a link.
And, here's the client program that #includes the above header:
http://coliru.stacked-crooked.com/a/7d6f8953f1cd766f
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include "my_math.h"
using namespace std;
int main()
{
cout << "add(2, 5) = "
<< add(2, 5) << endl;
cout << "multiply(2, 5) = "
<< multiply(2, 5) << endl;
}
|
To compile and link this program to the header, I issued the following commands:
1 2
|
ln -s /Archive2/c5/bc0bb639d621db/main.cpp my_math.h #link to the header file
clang++ -std=c++14 -stdlib=libc++ -O2 -Wall -Wextra -pedantic-errors -c main.cpp && echo ok
|
The output is as follows:
ln -s /Archive2/c5/bc0bb639d621db/main.cpp my_math.h #link to the header file
clang++ -std=c++14 -stdlib=libc++ -O2 -Wall -Wextra -pedantic-errors -c main.cpp && echo ok
ok
|
The program output doesn't appear.
So I have the following queries:
1) The 1st command links the client-program to the header.
2) The 2nd command compiles the client program.
3) There doesn't seem to be a command to run the executable. Is that why the program's output doesn't appear?
4) How can we run the executable?
5) Why is the link command issued before the compile command?
Thanks.