Click here to Skip to main content
14,937,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I wanted to create a makefile with a dynamic library attached. Unfortunately I get the message: error: rpath=.:There is no such file or directory. What am I doing wrong? My code looks like this:
main.c
#include <stdio.h>
#include <stdlib.h>

#include "calc.h"


int main()
{
int pick;
float a,b, result;

printf("====Pola Figur====\n");
printf("  \n");
printf("1. Pole prostokata\n");
printf("2. Pole kwadratu\n");
printf("3. Pole trojkata\n");
printf("4. Pole kola\n");
printf("  \n");
printf("Podaj wartosc: \n");
scanf("%d", &pick);
printf("  \n");
switch (pick){
case 1: 
printf("Wybrales pole prostokota. Wzor na pole prostokota to \"P=a*b\"\n");
printf("Podaj dlugosc boku a: ");
scanf("%f", &a);
printf("Podaj dlugosc boku b: ");
scanf("%f", &b);
result=rectangle(a,b);
printf("Pole prostokota wynosi: ");
printf("%f\n", result);
break;

case 2: 
printf("Wybrales pole kwadratu. Wzor na pole kwadratu to \"P=a*a\"\n");
printf("Podaj dlugosc boku a: ");
scanf("%f", &a);
result=square(a);
printf("Pole kwadratu wynosi: ");
printf("%f\n", result);
break;

case 3: 
printf("Wybrales pole trojkata. Wzor na pole trojkata to \"P=(a*h)/2\"\n");
printf("Podaj dlugosc boku a: ");
scanf("%f", &a);
printf("Podaj wysokosc trojkata: ");
scanf("%f", &b);
result=triangle(a,b);
printf("Pole trojkata wynosi: ");
printf("%f\n", result);
break;

case 4: 
printf("Wybrales pole kola. Wzor na pole kola to \"P=Pi*r^2\"\n");
printf("Podaj dlugosc promienia r: ");
scanf("%f", &a);
result=circle(a);
printf("Pole kola wynosi: ");
printf("%f\n", result);
break;

default: printf("Nie ma takiej opcji w menu");
}


return 0;
}

calc.h
#ifndef CALC_H
#define CALC_H

float rectangle(float a, float b);
float square(float a);
float triangle(float a, float b);
float circle(float a);
#endif

calc.c
#include "calc.h"
#include <math.h>

float rectangle(float a, float b)
{
return a*b;
}
float square(float a)
{
return a*a;
}
float triangle(float a, float b)
{
return a*b*0.5;
}
float circle(float a)
{
return a*a*M_PI;
}

and makefile
CC= gcc

all: main.o libfigure.so
	$(CC) main.o -Wl, rpath=. -L. -lfigure -o program

main.o: main.c
	$(CC) main.c  -c -o main.o

calc.o: calc.c
	$(CC) calc.c -c -o calc.o

libfigure.so: calc.o
	$(CC) -shared -fPIC calc.o


What I have tried:

I have no idea what could be wrong
Posted
Updated 3-May-21 16:16pm

Your makefile recipe for libfigure.so does not include the target name for the link phase, so gcc places the output in a.out, even for the shared library. You also need to use the -fPIC compile option during the compilation phase of the library objects, not the link phase. Also, there should not be a space after -Wl, and you need to specify -rpath=. So your makefile becomes
CC = gcc

program: main.o libfigure.so
        $(CC) main.o -Wl,-rpath=. -L. -lfigure -o program

main.o: main.c
        $(CC) main.c -c -o main.o
calc.o calc.c
        $(CC) calc.o -fPIC -c -o calc.o

libfigure.so: calc.o
        $(CC) -shared calc.o -o libfigure.so


If you are doing things with shared libraries, or even static libraries, you should probably take a look at Libtool[^] which can help with all the intricacies of building libraries.
   
$(CC) main.o -Wl, rpath=. -L. -lfigure -o program
The problem is the line above and the space between the , and rpath. Generally, when passing along an argument to the linker via -Wl there is no space after the comma.

Refering to this page : Option Summary (Using the GNU Compiler Collection (GCC))[^], I'm not entirely sure what you are trying to do.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900