Hi i am a beginner learning objective c.
i am finding an error "hello.m:1:34: Foundation/Foundation.h: No such file or directory"
i came to know that i need to make a make file
may i know how to make the make file please
No need to create a makefile. If you start MinGW from "All Programs -> GNUstep -> Shell" as Pax indicates above, you can just compile your .m file.
My GNUstep installation is in c:\GNUstep\GNUstep\System. If yours is different, you should change the import of Foundation.h accordingly.
I did this:
Create c:\myprogs\obj-c\hello\hello.m that looks like this:
//---------- Hello.m
#import <../../GNUstep/System/Library/Headers/Foundation/Foundation.h>
int main(int argc, const char* argv[])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSLog(#"Hello from Hello.m!");
[pool release];
return 0;
}
//----------
Start MinGW shell. (See above.)
On shell command line, change to directory where program code is located. (Note that, since this is not Unix, the Windows drive letter must be included.):
cd /c/myprogs/obj-c/hello
Compile the program:
gcc -o hello hello.m -I/c/GNUstep/GNUstep/System/Library/Headers \
-L /c/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base \
-fconstant-string-class=NSConstantString
(Note that "\" character allows us to extend command to multiple lines.)
I get the following informational messages when I compile:
Info: resolving ___objc_class_name_NSAutoreleasePool by linking to __imp____objc_class_name_NSAutoreleasePool (auto-import)
Info: resolving ___objc_class_name_NSConstantString by linking to __imp____objc_class_name_NSConstantString (auto-import)
Running resulting hello.exe gives me this:
2009-06-03 14:44:59.483 hello[1240] Hello from Hello.m!
That problem just looks like you haven't instructed gcc on where to find the relevant include files (i.e., the directory in which Foundation/Foundation.h resides).
Are you running gcc from under MinGW or from the command prompt. You should have a "All Programs -> GNUstep -> Shell" on your Start menu which brings up this shell.
A makefile for this should be as simple as:
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = YourProg
YourProg_OBJC_FILES = source_code.m
include $(GNUSTEP_MAKEFILES)/tool.make
If you will put your source codes into home directory in GNUStep, you don't need to provide relative location of Foundation framework.
Using a makefile such as the one specified by paxdiablo is probably the easiest, because rather than trying to remember an arcane command line each time, you set up the makefile and then call make from the source folder.
However, my experience under Windows suggested that GNUStep and Windows, even with the shell, won't build using that because it can't find all the make files it needs - add an environment variable GNUSTEP_MAKEFILES with a value of /GNUstep/System/Library/Makefiles and restart that shell, and then any errors from it being unable to find the standard makefiles should be history.
(I had tried using full paths to the makefiles, but found that this included the specific makefiles but then failed when trying to include further ones, hence going the easy route and adding an environment variable.)
Related
I am trying to create a CMake C99 project that will have an embedded resource that can be read by the project. And this project should be portable. I am actually using CLion but I think this is a just CMake question.
Ideally I would like to see a simply way to embed helloworld.txt file in the CMake project and then a way to read the contents into const char* helloword_txt = ?? variable. And then have this compile with GCC or a Microsoft C++ compiler.
I have looked at the CMakeRC.cmake project but that look like a C++ specific way. I looked at commands like ld -r -b binary -o binary.o foo.bar # then link in binary.o but that look like Linux-specific way.
I thought CMake was designed for portable projects. Is there a portable way to do this?
I doubt there is a independent resource management system available. At least, I don't know of any.
You can take a look at Qt's qrc - it is more or less portable, but introduce a Qt dependency, of course.
First I would use FILE *fopen( const char *restrict filename, const char *restrict mode ) from C99 Standard.
Then in CMake I would use install(FILES helloworld.txt DESTINATION ${CMAKE_INSTALL_BINDIR})
note: CMAKE_INSTALL_BINDIR comes from GNUInstallDirs built-in module.
Then using a bash/bat script you can always run the program from the "BIN_DIR" so the path to helloworld.txt is "."
e.g. add_executable(foo_prg ...) ... install(TARGETS foo_prg ...)
/usr/bin/foo:
#!/usr/bin/env bash
cd /usr/bin && ./foo_prg
So user can run ./foo which will "trampoline" to /usr/bin to run foo_prg binary
Note: To test without installing, you can add to CMake:
file(COPY helloworld.txt DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
note: does not work for multi-configuration build but should be easy to deduce.
note2: don't know (i.e. never tested) if we can use $<TARGET_PROPERTY:foo_prg,RUNTIME_OUTPUT_DIRECTORY> instead.
I'm on Ubuntu 12.
I'm trying to compile an Objective-C hello_world app using clang. This is the source:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (#"hello world");
[pool drain];
return 0;
}
I use this commandline:
. /usr/share/GNUstep/Makefiles/GNUstep.sh
clang h.m `gnustep-config --objc-flags` -lgnustep-base -o hello
I get the following error:
clang: warning: argument unused during compilation: '--param ssp-buffer-size=4'
In file included from h.m:1:
In file included from /usr/include/GNUstep/Foundation/Foundation.h:30:
In file included from /usr/include/GNUstep/GNUstepBase/GSVersionMacros.h:193:
In file included from /usr/include/GNUstep/GNUstepBase/GSConfig.h:229:
/usr/include/GNUstep/GNUstepBase/preface.h:112:11: fatal error: 'objc/objc.h'
file not found
#include <objc/objc.h>
^
1 error generated.
The same commandline using gcc works fine.
Any ideas how to fix this missing objc.h error?
obj-c.h is part of the Objective-C runtime, have you got that installed? From my own experience GNUstep seems to be a world of hurt on most platforms, so it may simply be GNUstep's configure scripts refusing to pick it up even if it is installed, try their mailing list if you can't get a better answer here.
That header comes as part of the ObjC-Runtime. While GCC provides a runitme (although one only without the modern features like ARC), Clang/LLVM doesn't sport such a runtime. If you want to use Clang, you need to install GNUstep's ObjC runtime , which you can find here:
https://github.com/gnustep/libobjc2
For Ubuntu, there are bash scripts available at the GNUstep-wiki, which help you in the somewhat complicated GNUstep installation process:
http://wiki.gnustep.org/index.php/GNUstep_under_Ubuntu_Linux
and one more tip: you should not try to reinvent GNUstep-make by trying to use the compiler manually, like you did. Better use GNUstep-make:
http://www.gnustep.org/resources/documentation/Developer/Make/Manual/gnustep-make_1.html
I am newbie on MacOs. Today I had to build pyobjc Cocoa python wrapper in nix and have to deal with clang. I had similar error. As any C developer first I extended CFLAGS with I/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include, but it didn't change anything. After scratching my head for quite awhile I tried to call clang manually just with -I and it was working! So -isysroot disables -I and doesn't do anything on its own. I found -iwithprefix and put it with path I used with -I and it works with -isysroot, which I cannot easily remove - it is injected somewhere inside nix derivations into CLFAGS.
I have a question relating to this question Unable to Compile Objective C using Gnustep on windows
I am trying to compile my first objective c app on Windows.
The file is hello.m (all files below created in Visual Studio)
#import <../Program Files/GNUstep/System/Library/Headers/Foundation/Foundation.h>
int main(int argc, const char* argv[])
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSLog(#"Hello from Hello.m!");
[pool release];
return 0;
}
In order to compile it I have a GNUmakefile in the same directory:
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = hello
YourProg_OBJC_FILES = hello.m
include $(GNUSTEP_MAKEFILES)/tool.make
As I understand it, when I run make the command "make" the GNUmakefile will execute.
When I do this in the GNUStep shell I get an error
GNUmakefile:1 *** missing separator. Stop.
I tried adding a tab to the first line. This did nothing. Yes, I am sure it was a tab, not a space.
I Had the same problem. I used Notepad++ to make the GNUmakefile. My default encoding with Notepad++ is UTF8. But make.exe from MINGW32 seems to wait a file with ANSI encoding.
So, verify if your file is encoded with ANSI.
make is complaining about your makefile, so you probably have a syntax error somewhere.
See: http://www.gnu.org/software/automake/manual/make/Error-Messages.html:
This means that make could not understand much of anything about the makefile line it just read. GNU make looks for various separators (:, =, recipe prefix characters, etc.) to indicate what kind of line it's parsing. This message means it couldn't find a valid one.
Try you might try compiling directly:
gcc -o hello hello.m -I/c/GNUstep/GNUstep/System/Library/Headers \
-L /c/GNUstep/GNUstep/System/Library/Libraries -lobjc -lgnustep-base \
-fconstant-string-class=NSConstantString
you should never have to provide the full path for the Foundation.h header file.
It should always be #import <Foundation/Foundation.h>.
This together with your makefile problem indicate that something is not setup correctly on your machine.
Did you run the make command from an msys shell or from the Windows commandline?
If you chose to go with the Windows command line you will face some problems because the environment is not setup correctly there in contrary to the msys shell provided with the GNUstep installer.
If you want to run gcc manually on the other hand you can have a look at this SO answer.
In your GNUmakefile, YourProg_OBJC_FILES should be modified to be hello_OBJC_FILES, just like below
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = hello
hello_OBJC_FILES = hello.m
include $(GNUSTEP_MAKEFILES)/tool.make
Or you can also just compile in command line like this
$ gcc `gnustep-config --objc-flags` hello.m -o hello `gnustep-config --base-libs`
The gnustep-config like pkg-config command can print out the compiling and linking options for gcc.
I am going to build a Mac application written in Obj-C with Xcode. For argument's sake let's say it will have 10 optional features. I need a way to enable or disable those features to create custom builds of the application. These builds would be automated (most likely through the Mac OS X Terminal) so I would need a way to state which of these features are enabled/disabled at build time (a configuration file or CLI arguments would be ideal.)
So what is the best way to accomplish this? I'm trying to plan this out before I start coding so that there is proper separation in my code base to allow for these features to come and go. Ideally the custom build would only contain compiled code for the features it should have. In other words I don't want to always compile all the features and condition them out at runtime.
You can use Xcode configurations for this purpose; for each configuration you could include a different prefix header, for example. Then you can trigger builds form the command line via xcodebuild.
If you'd prefer the config file approach, you can use a .xcconfig file instead to define any of the Xcode build settings.
The Xcode Build System Guide describes both of these approaches.
use #ifdef and the -D flag under the compiler flags to control whether stuff is compiled in or out. You can set up lots of different configs this way if you want, and just have the xcode build configurations work nicely.
#include <stdio.h>
int
main (void)
{
#ifdef TEST
printf ("Test mode\n");
#endif
printf ("Running...\n");
return 0;
}
output 1:
$ gcc -Wall -DTEST dtest.c
$ ./a.out
Test mode
Running...
output 2:
$ gcc -Wall dtest.c
$ ./a.out
Running...
source: http://www.network-theory.co.uk/docs/gccintro/gccintro_34.html
If I compile this QT c++ program in SuSE Linux
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!";
return 0;
}
When I type
i386-mingw32-g++ helloworld.cpp
I get the following error
i386-mingw32-g++: error trying to exec 'cc1plus': execvp: No such file or directory
Is this because MinGW package which i installed contains only gcc in it.. hence i downloaded gcc-g++-3.4.5.rpm package and just copy pasted i386-mingw32-g++ and cc1plus executable along with C++ include files.
Pls reply.
Thanking You
Ugh. The cc1plus in gcc-g++-3.4.5.rpm is not for mingw32. You need the one for your distro.
e.g. for Fedora 10, use http://sourceforge.net/projects/outmodedbonsai/files/Mingw%20Cross-compiler/mingw-1.10-1.fc10.x86_64.rpm
Quoting from here:
It means that your shell could find
the g++ frontend of the GNU compiler
but that frontend couldn't find
cc1plus, the actual C++ compiler; it
could find cpp, the preprocessor, it
already ran. Go to the directory where
the g++ frontend is stored (type:
"which g++") and look for the file
cc1plus in that same directory or a
sub- directory thereof. If it isn't
there your compiler installation is
broken; if it is there some
configuration of it went berzerk.
Also, have a look at this thread.
suse cross-compile toolchain is here.
http://download.opensuse.org/repositories/CrossToolchain:/mingw/