Solution for "'glog/logging.h' file not found" error in React Native


The error "'glog/logging.h' file not found" in React Native, it typically indicates that the required Google logging library is missing or not properly configured. This error commonly occurs when you're trying to compile a module or a package that depends on this library but it's not available in your project.

Possible Causes:

  • Missing installation of required dependencies.
  • Incorrect configuration of the project.

Solution:

  1. Check Dependencies: Make sure you have all the necessary dependencies installed. In this case, you need to ensure that the Google logging library is included.

    Run the following command to install the required dependencies:

    npm install --save glog
  2. Linking Dependencies: Sometimes, even after installing the dependency, you might need to link it manually to your project.

    If you're using React Native version 0.60 or above, linking is done automatically. For older versions, you might need to link it manually:

    react-native link glog
  3. Check Project Configuration: Ensure that your project is correctly configured to use the Google logging library. Check if the library paths are correctly set in your project configuration files.
  4. Clean and Rebuild: After making any changes, clean your project and rebuild it to ensure that the changes are properly reflected.

    For iOS:

    cd ios && pod install && cd .. && react-native run-ios

    For Android:

    cd android && ./gradlew clean && cd .. && react-native run-android

Example:

Let's consider an example where we encounter this error while trying to compile a React Native project:

// Sample React Native code
#include "glog/logging.h"

int main() {
    // Your code here
    return 0;
}

In this example, the inclusion of glog/logging.h leads to the error. Following the steps outlined above can resolve this issue.

Ensuring that React Native is fully installed


  • We start by ensuring that React Native is fully installed in our node_modules folder. If it's not installed completely, we reinstall it to make sure everything is in place.
  • Next, we navigate to the root directory of our system or project path where npm is installed on our computer.

Then, we execute a series of commands in the terminal:

cd ./node_modules/react-native && scripts/ios-install-third-party.sh && cd third-party && cd $(ls | grep 'glog' | awk '{print $1}') && ./configure

These commands essentially take us to the glog module directory within the React Native installation and run the ./configure script to configure glog.

To ensuring that all necessary dependencies are in place and properly configured. By following these steps, we can address any issues related to the installation and configuration of React Native and its third-party modules, such as glog.

Uses a relative path


Here's what we've uncovered: assuming we're starting from our project's root directory, we need to navigate to the glog module directory. So, we run:

cd node_modules/react-native/third-party/glog-0.3.4

Once we're in the glog module directory, we execute the ios-configure-glog.sh script by running:

sh ../../scripts/ios-configure-glog.sh

Now, let's delve into our take on this solution. The ios-configure-glog.sh script relies on a relative path to the ./configure script. This means that if we don't change the directory or specify the correct path beforehand, it's going to throw an error.

By following these steps and either changing to the correct directory or providing the correct path to the script, we ensure that the configuration process runs smoothly. It's a small adjustment, but it can save us a lot of frustration and troubleshooting time in the long run.