Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefix_header_file are not Headmost #12730

Open
iStarEternal opened this issue Dec 20, 2024 · 1 comment
Open

prefix_header_file are not Headmost #12730

iStarEternal opened this issue Dec 20, 2024 · 1 comment

Comments

@iStarEternal
Copy link

Code: prefix_header.rb

OpenCV need import <opencv2/opencv.hpp> before others import。

#if defined(NO)
#  warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
#endif

But prefix_header not supported generate prefix_header_file foremost.

So I fix it in Podfile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = "13.0"
    end
  end
  # 插入这一句,解决OpenCV编译报错
  prefix_pch_path = 'Pods/Target Support Files/LPOpenCV/LPOpenCV-prefix.pch'
    if File.exist?(prefix_pch_path)
      content_to_add = <<-OPEN_CV_HEADER
// ↓ --- 解决OpenCV的问题:warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#import <opencv2/imgproc/types_c.h>
#import <opencv2/core.hpp>
#import <opencv2/features2d.hpp>
#import <opencv2/calib3d.hpp>
#import <opencv2/objdetect.hpp>
#import <opencv2/highgui.hpp>
#import <opencv2/imgproc.hpp>
#import <opencv2/objdetect/objdetect.hpp>
#endif
// ↑ ---
      OPEN_CV_HEADER

      File.open(prefix_pch_path, 'r ') do |file|
        old_content = file.read
        file.rewind
        file.puts content_to_add   old_content
      end
    end
end

Could you exchange prefix_header_file generated order with prefix_header.rb?

def generate
        result = super

        unique_prefix_header_contents = file_accessors.map do |file_accessor|
          file_accessor.spec_consumer.prefix_header_contents
        end.compact.uniq

        unique_prefix_header_contents.each do |prefix_header_contents|
          result << prefix_header_contents
          result << "\n"
        end

        file_accessors.map(&:prefix_header).compact.uniq.each do |prefix_header|
          result << Pathname(prefix_header).read
        end

        result
      end

def generate
        result = ""

        unique_prefix_header_contents = file_accessors.map do |file_accessor|
          file_accessor.spec_consumer.prefix_header_contents
        end.compact.uniq

        unique_prefix_header_contents.each do |prefix_header_contents|
          result << prefix_header_contents
          result << "\n"
        end

        file_accessors.map(&:prefix_header).compact.uniq.each do |prefix_header|
          result << Pathname(prefix_header).read
        end
       
       result << super
       
        result
      end
@iStarEternal
Copy link
Author

3Q and Kissu 😘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant