Thread: Including a library

  1. #1
    Registered User
    Join Date
    Oct 2014

    Including a library


    This is literally my first time trying to add a library into my C/C++ program. The library I want to add is FreeType. Also, I'm using Windows 7, if that matters, and MinGW-64 bit compiler.

    So far I have managed to get the include path correctly.
    #include "jni.h"
    #include <iostream>
    #include <ft2build.h>
    #include FT_FREETYPE_H
    extern "C" JNIEXPORT void JNICALL Java_FreeType_enter(JNIEnv *env, jobject obj, jint integer)
        FT_Library  library;
        std::cout << "Hello world!" << std::endl;
    I get the following code to compile correctly with this line:
    g++ -Werror -Ilibs/jni/include -Ilibs/freetype/include -shared -o lib.dll FreeType.cpp
    This code compiles successfully and the program executes properly.

    My problem comes when I actually need to use FreeType functions. When I add this line of code to my 'enter'
    FT_Init_FreeType( &library );
    compiler gives me an error that reference to FT_Init_FreeType is undefined.

    I have found this topic on stackoverflow freetype - C compiler error: Undefined reference to 'FT_Init_FreeType' - Stack Overflow, however it didn't help me much, as I tried many different combination of -L and -l parameters, and compiler kept saying that it cannot find the file specified.

    Sorry if I posted in the wrong board, and thank you for your time in advance!

  2. #2
    Registered User
    Join Date
    Dec 2007
    Find the directory the library file, libfreetype.a, is in. If it's in /a_directory/a_subdirectory, then your command line should probably look like

    g++ -Werror -Ilibs/jni/include -Ilibs/freetype/include -shared -o lib.dll FreeType.cpp -L/a_directory/a_subdirectory -lfreetype

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Including library's
    By Libpgeak in forum C Programming
    Replies: 3
    Last Post: 04-27-2012, 01:03 AM
  2. Replies: 9
    Last Post: 02-08-2012, 10:23 PM
  3. including a static library!
    By hmd in forum C Programming
    Replies: 1
    Last Post: 04-06-2008, 03:41 PM
  4. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  5. Including Library...
    By Da-Spit in forum Game Programming
    Replies: 2
    Last Post: 05-29-2002, 12:22 AM