Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is -L needed when -rpath is used?

Tags:

I find that the -L flag must be given when using -rpath. For instance:

gcc -o test test.o -L. -lmylib -Wl,-rpath=. 

Why is the -L flag needed? What information more than the information from the h-files are needed at compile time?

If I remove -L. I get the following message:

gcc -o test test.o -lmylib -Wl,-rpath=. /usr/bin/ld: cannot find -lmyLib 

It's perfectly ok to remove both flags, though. Like this:

gcc -o test test.o -lmylib 

Provided that libmyLib can be found in /usr/lib, that is. Why isn't -L needed now?

This is a follow-up question to https://stackoverflow.com/a/8482308/1091780.

like image 558
Fredrik Johansson Avatar asked Jan 22 '15 18:01

Fredrik Johansson


People also ask

How do you know if mocked method called?

To check if a method was called on a mocked object you can use the Mockito. verify method: Mockito. verify(someMock).

What is Mockito verify used for?

Mockito Verify methods are used to check that certain behavior happened. We can use Mockito verify methods at the end of the testing method code to make sure that specified methods are called.

What is verifyNoMoreInteractions?

verifyNoMoreInteractions() public static void verifyNoMoreInteractions(Object... mocks) Checks if any of given mocks has any unverified interaction. We can use this method after calling verify() methods.

How do you check whether a method is called in Mockito?

Verify in Mockito simply means that you want to check if a certain method of a mock object has been called by specific number of times. When doing verification that a method was called exactly once, then we use: ? verify(mockObject).


1 Answers

Even dynamic libraries required a degree of static linkage; the linker needs to know what symbols should be supplied by the dynamic library. The key difference is that the dynamic library provides the definition at runtime, whilst with fully static library provides the definition at link time.

For this reason, -L is needed to specify where the file to link against is, just as -l specifies the specific library. The . indicates the current directory.

-rpath comes into play at runtime, when the application tries to load the dynamic library. It informs the program of an additional location to search in when trying to load a dynamic library.

The reason -L/usr/lib doesn't need to be specified is because the linker is looking there by default (as this is a very common place to put libraries).

like image 118
OMGtechy Avatar answered Jan 01 '23 13:01

OMGtechy