This is the error I have been getting.
-bash-4.1$ g++ strl.cpp -o -lc-
/tmp/ccRpiglh.o: In function `main':
strl.cpp:(.text+0xf): undefined reference to `plusplus'
collect2: ld returned 1 exit status
Hear is the source code for strl.cpp. This is a simple example that duplicates my problem.
strl.cpp
#include <iostream>
#include <stdlib.h>
#include "libc-.h"
using namespace std;
int main()
{
cout<<plusplus(5,2)<<'\n';
}
Here is the source for libc.cpp
libc.cpp
#include <iostream>
using namespace std;
int plusplus(int a, int b)
{
return a + b;
}
Source for libc-.h
libc-.h
#ifndef _SCANTYPE_H_
#define _SCANTYPE_H_
#include <iostream>
#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
#endif
using namespace std;
int plusplus(int a, int b);
#ifdef __cplusplus
}
#endif
#endif
I am compiling with the following:
g++ -Wall -shared -fPIC -o libc-.so libc-.cpp
g++ strl.cpp -o -lc-
g++ -Wall -shared -fPIC -o libc-.so libc-.cpp
compiles without error.
Why is function plusplus
an undefined reference?
Thanks for any insight as to what I am doing wrong.