Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: quick q on path

  1. #1
    Intern Contributor
    Join Date
    May 2017
    Posts
    80

    quick q on path

    I am going to start keeping all of my libs, bins, and include files in one lib folder, one bin folder and one include file folder. My question is how do I "get" to the header files on my .cpp file without a verbose file /directory line. I use MingW and its easy with <GL/glut.h> etcetera. But what if I want to place my header file "system" address elsewhere. Do I write a new path code? I am not suggesting altering MinGW at all just a different address for something new.

    Ideally I would like to save my includes at c:/software/includes; how do I create a path for this for compiler use like <GL/glut.h>?
    Last edited by technologist; 06-22-2017 at 09:14 PM. Reason: inaccurate

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,173
    I don't know much about MinGW, but it uses GCC, right?

    If so, this may be relevant:
    * 2.3 Search Path (GNU CPP docs)

    So the simple solution is to just include these extra include paths on the compiler command-line with -I<path> options.

    There's also finding libraries in search paths and adding those to the link command-lines as well (e.g. -L<path>, -l<library>, etc.)

    For starters, you can do this yourself so you know how it works. Then an easy next-step is to encode these commands you're running into a Makefile so that you can build everything just by typing "make" in your source directory.

    An even higher level than that is to use something like CMake to automate searching for headers and libraries on your system and building a custom Makefile (and/or MSVS solution/project files) which will build your application.

    Here's a short Makefile tutorial to get you started: Makefiles: A Tutorial by Example. The syntax is simple. You'll have this mastered in minutes. I'd recommend doing this first.

    Later once you want to automate finding includes and libraries on your system (and/or supporting multiple PCs and platforms), here's a simple "CMakeLists.txt" input file for CMake that automates the generation of both: 1) MSVS solution/project files on Windows, and 2) Makefile generation on Linux for some GLUT+GLEW example programs. The generated build files will build executables for these examples.

    Code :
    cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
     
    # Help Windows find libaries
    if ( WIN32 )
      # NOTE: You should add these directories to your PATH (for .dlls):
      #           C:\Tools\glew-2.0.0\bin\Release\Win32
      #           C:\Tools\freeglut-3.0.0\bin
      set(CMAKE_PREFIX_PATH "C:/Tools/glew-2.0.0;C:/Tools/freeglut-3.0.0")
      set(CMAKE_LIBRARY_PATH "C:/Tools/glew-2.0.0/lib/Release/Win32;C:/Tools/freeglut-3.0.0/lib")
    endif()
     
    # Find packages of additional libraries
    #   - GLEW
    find_package( GLEW REQUIRED )
    if ( GLEW_FOUND )
        include_directories( ${GLEW_INCLUDE_DIRS} )
        link_libraries     ( ${GLEW_LIBRARIES}    )
    endif()
     
    #   - GLUT
    find_package( GLUT REQUIRED )
    if ( GLUT_FOUND )
        include_directories( ${GLUT_INCLUDE_DIR} )
        link_libraries     ( ${GLUT_LIBRARIES}    )
    endif()
     
    #   - OpenGL
    find_package( OpenGL REQUIRED )
    if ( OPENGL_FOUND )
        include_directories( ${OPENGL_INCLUDE_DIRS} )
        link_libraries     ( ${OPENGL_LIBRARIES}    )
    endif()
     
    # C++11
    macro(use_cxx11)
      if (CMAKE_VERSION VERSION_LESS "3.1")
        if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
          set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
        endif ()
      else ()
        set (CMAKE_CXX_STANDARD 11)
      endif ()
    endmacro(use_cxx11)
     
    use_cxx11()
     
    # Specify exec_name followed by source and header files
    add_executable ( tst                       tst.cpp                      )
    add_executable ( probe_gl                  probe_gl.cpp                 )

    To use cmake to build, you just do something like this:
    Code :
    # One-time setup
    mkdir build
    cd build
    cmake ..
     
    # To build your code, use one of the following two commands.
    # 
    make
      OR
    cmake --build .
    Last edited by Dark Photon; 06-23-2017 at 06:39 AM.

  3. #3
    Intern Contributor
    Join Date
    May 2017
    Posts
    80
    Absolutely right!

    So the simple solution is to just include these extra include paths on the compiler command-line with -I<path> options.

    There's also finding libraries in search paths and adding those to the link command-lines as well (e.g. -L<path>, -l<library>, etc.)
    Yes, and I use these in-IDE all the time. Problem is what if I for example I have GLUT ( a lot on that lately, have working copies now ) not in the system path <GL/glut> but in a farmed out region for all includes (e.g. c/software/recent_downloaded/includes/) - outrageous example.

    HOW is this done?#include<c/software/recent_downloaded/includes/glut.h>
    Seems outrageous and verbose. Do you see my question?

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,526
    Quote Originally Posted by technologist View Post
    HOW is this done?#include<c/software/recent_downloaded/includes/glut.h>
    That typically won't work, because if glut.h needs to include any other headers which are in your non-system header directory, the compiler won't know where to find them.

    So you need to use -I switches, e.g.
    Code :
    -I/c/software/recent_downloaded/includes

    Also, if you want to work with existing code, glut.h needs to go into a directory called "GL", because glut.h is invariably included using
    Code :
    #include <GL/glut.h>
    Any -I switches shouldn't include the "GL" subdirectory.

  5. #5
    Intern Contributor
    Join Date
    May 2017
    Posts
    80
    So basically the bottom line is I can make a

    library
    binary

    farm

    but I've got to keep header files in arms reach of my mingW processor of its current directory structure.

    Ok, no big deal I guess.

  6. #6
    Intern Contributor
    Join Date
    May 2017
    Posts
    80
    Quote Originally Posted by GClements View Post
    That typically won't work, because if glut.h needs to include any other headers which are in your non-system header directory, the compiler won't know where to find them.

    So you need to use -I switches, e.g.
    Code :
    -I/c/software/recent_downloaded/includes

    Also, if you want to work with existing code, glut.h needs to go into a directory called "GL", because glut.h is invariably included using
    Code :
    #include <GL/glut.h>
    Any -I switches shouldn't include the "GL" subdirectory.
    I'm using the "I" switches in the Eclipse IDE and i works well. But that still doesn't buy me a dedicated source folder though right?

  7. #7
    Intern Contributor
    Join Date
    May 2017
    Posts
    80
    FOLLOW UP: I'm able to use all headers in other folders successfully with -lpath and then -include, "pulling" from an "isolated" folder of headers into Eclipse.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •