Click here to Skip to main content
15,879,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I build my project(Face_test.cpp), I need this command:
g++ -std=c++11 -O3 -I.. ../dlib/all/source.cpp -DDLIB_JPEG_SUPPORT -DDLIB_PNG_SUPPORT -ljpeg -lpng -lpthread -lX11 -fPIC -shared -o Face_test.cpp

But I expect to build it via command like:
g++ Face_test.cpp -L. -lFace -o Face_test

which means I need to build my library. So how can I build my library?

What I have tried:

I've tried to build my library(libFace.so) via command like:
g++ -std=c++11 -O3 -I.. ../dlib/all/source.cpp -DDLIB_JPEG_SUPPORT -DDLIB_PNG_SUPPORT -ljpeg -lpng -lpthread -lX11 -fPIC -shared -o libFace.so
and then,
g++ Face_test.cpp -L. -lFace -o Face_test

but it did not work, and throws error like this:
Face_test.cpp:41:57: fatal error: dlib/image_processing/frontal_face_detector.h: No such file or directory
compilation terminated.

So I have one more question: why I still need *.h when I have a *.so?

Can anyone give me some hints.
Posted
Updated 22-Jun-17 21:23pm
v2

1 solution

The process of creating an executable uses two steps:

  1. Compile each source file to create corresponding object files
  2. Linking the object files to create an executable or a library

Because your project is also building a library, you have to do the second step twice (one time for the library and one time for the executable).

The G++ can perform both steps (compiling and linking) with one command. This is usually done with small builds containing only a single or a few source files. Each process (compiling and linking) has it's own set of process specific command line options.

The error
Face_test.cpp:41:57: fatal error: dlib/image_processing/frontal_face_detector.h: No such file or directory
compilation terminated.
occurs when compiling the source file Face_test.cpp. It tells you that the include file from the message could not be found. It is not related to any library because it happened during compilation (not linking).

Knowing now about the two build steps you should become familiar with the related options (Invoking GCC - Using the GNU Compiler Collection (GCC)[^]).

If your first command (compiling the file source.cpp and linking it to create the shared library libFace.so) succeeds, you have to compile the file Face_test.cpp and link the generated object file with your library to generate the executable. But the command
g++ Face_test.cpp -L. -lFace -o Face_test
did not contain any compiling options as in your previous calls. So just add these:
g++ -std=c++11 -O3 -I.. Face_test.cpp -L. -lFace -o Face_test

I don't know your setup so that it might be neccesary to add more options (e.g. -I../dlib/image_processing which should definitely avoid the error).
 
Share this answer
 
Comments
Sar Kerson 24-Jun-17 4:26am    
Thank you so much! I just used the command: g++ -std=c++11 -O3 -I.. Face_test.cpp -L. -lFace -o Face_test
And, it did work!
Jochen Arndt 24-Jun-17 4:49am    
Thank you for your feedback.

You might accept my solution so that it is marked as solved.

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