How to add Objective-C code to a FireBreath project?

I am writing a browser plug-in for Mac OS that places a status bar icon in a status bar that users can use to interact with a browser plug-in. I have successfully built the FireBreath 1.6 project in Xcode 4.4.1 and can install it in a browser. However, FireBreath uses C ++, while most of the existing libraries for Mac OS are written in Objective C.

In the /Mac/projectDef.make file, I added the Cocoa Framework and Foundation Framework, as suggested here , and in other resources that I found on the Internet:

target_link_libraries(${PROJECT_NAME} ${PLUGIN_INTERNAL_DEPS} ${Cocoa.framework} # added line ${Foundation.framework} # added line ) 

I reran prepmac.sh, expecting a new project to be created in Xcode with my .mm and .m files; however, they seem to be ignored. I only see .cpp and .h files. I added rules for those found in the projectDef.make file, but it doesn't seem to matter:

 file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} Mac/[^.]*.cpp Mac/[^.]*.h Mac/[^.]*.m #added by me Mac/[^.]*.mm #added by me Mac/[^.]*.cmake ) 

Even if I add the files manually, I get a number of compilation errors. There are about 20 of them, all associated with the NSObjRuntime.h file:

 Parse Issue - Expected unqualified-id Parse Issue - Unknown type name 'NSString' Semantic Issue - Use of undeclared identifier 'NSString' Parse Issue - Unknown type name 'NSString' ... ... Semantic Issue - Use of undeclared identifier 'aSelectorName' ... ... Semantic Issue - Use of undeclared identifier 'aClassName' ... 

This has been going on for some time with similar errors ...

From what I read, these errors appear due to dependencies on the Foundation Framework, which I believe are included in the project. I also tried clicking a project in Xcode

Now I want to say where I’m not sure what to do next. People say it's not difficult to use Objective-C in C / C ++ code, but being new to Xcode and Objective-C can contribute to my confusion. This is only the 4th day for me on this new platform.

What do I need to do to get Xcode to compile Objective-C code? Please remember that I'm a little new to this, so I would appreciate it if you would leave detailed answers, rather than the vague single-line that are common in the firebreath message. I’m just a little over my head, but if you can overcome this obstacle for me, I’m sure that I’ll go well from there.

UPDATE:

I edited the /MyPlugin/CMakeLists.txt projects and added them in the .m and .mm rules. after starting prepmac.sh, the files are included in the project, but I still get the same compilation errors.

I moved all the .h and .mm files from the Obj C code to the MyPlugin root folder and rerun the prepmac.sh file. The problem still exists. The same compilation errors.

+4
source share
1 answer

Your problem is that you have .h files that are included in C ++ files that have the object type c and / or are included in them. To do what you want, all of your C ++ classes should either contain all the things related to it in #ifdef, or just not show anything in the header file.

For example, you can use this ifdef in your header:

 #ifdef __OBJC__ // Objective C / C++ code here #endif 

It is important to remember that .h files also include header files, so they are actually included. If you include the c object code in a .cpp file, the compiler gets confused and cries.


EDIT: The most important thing to remember is that you need to make sure that any object c header files (or other files with objective c code) are not included in cpp files. If you can do this, everything will be all right.

+2
source

Source: https://habr.com/ru/post/1433054/


All Articles