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.
Related
I am starting in the world of LLVM and searched in several places and read several documentation about LLVM but I found nothing showing how to compile a program that uses LLVM headers and libs ....
I wrote this simple program just to try to compile, using the Visual Studio cross-compiler, I tried several command line options .... even using the -lLLVM option, but, nothing worked ...
I tried using g++ and clang++
#include <iostream>
#include <llvm/ADT/OwningPtr.h>
#include <llvm/Support/MemoryBuffer.h>
int main()
{
llvm::OwningPtr<llvm::MemoryBuffer> buffer
return 0;
}
When I try to build, I get this erro:
error : 'llvm/ADT/OwningPtr.h' file not found
So, what is the command line to compile this simple program?
The command llvm-config --cxxflags --ldflags --system-libs --libs core will provide you with all the linkable llvm libraries, provided you have llvm installed. Just link with this command in single quotes
I'd like to be able to view preprocessor output in order to make sure my preprocessor directives run correctly. Dev-C++ has an option in Tools > Compiler Options... > General to add commands when calling the compiler, and I've added the command -E C:\Personal\preprocessed.cpp. I got a compiler error saying the file didn't exist, but shouldn't the compiler just create the file in that case? I created the file, and now I'm getting this error: cannot specify -o with -c, -S or -E with multiple files.
Why am I using Dev-C++ instead of Visual Studio? Since I'm still learning, I'd like to be able to test just a few lines of code without having to create an entire new project.
Yes, I've seen this question and no adequate answer was given. Please don't mark this as a duplicate.
Thanks in advance for your help!
I've added the command -E C:\Personal\preprocessed.cpp. I got a compiler error saying the file
didn't exist, but shouldn't the compiler just create the file in that case?
No, because the -E option
takes no argument, filename or otherwise. It simply instructs the
compiler to do nothing but preprocessing. The preprocessed code is written to the standard output. Thus:
Thus:
g++ -E C:\Personal\preprocessed.cpp foo.cpp
tells the compiler that you want run g++ -E with the pair of input files C:\Personal\preprocessed.cpp and foo.cpp,
which as you've discovered is not allowed.
The simple thing that you want to do is absurdly difficult with your IDE of choice. Assuming
the source file you want to preprocess is C:\Personal\foo.cpp and the g++ is in your PATH,
just open a command window in C:\Personal and run:
g++ -E foo.cpp > foo.ii
I suggest the output file foo.ii - though you can call it whatever you like - because g++ recognizes the extension .ii as denoting C++ source code that has already been preprocessed. You can run:
g++ -Wall -o prog foo.ii
and foo.ii will be compiled and linked as program prog without being preprocessed again.
I have configure.ac which is designed for building a shared library (both linux and macos). Now I'd like to add special demo app which uses this library and shows its features. However this demo app is only for MacOS and has .mm file in it (main.mm). I'm trying to define a target for this demo app in this way:
if OS_DARWIN
EXTRA_PROGRAMS = app-demo
app_demo_CC = OBJC
app_demo_CXX = OBJC
app_demo_SOURCES = demoapp/config.cc demoapp/config.h \
demoapp/main.mm demoapp/AppDelegate.m \
demoapp/renderer-stub.cc demoapp/renderer-stub.h \
demoapp/view.cc demoapp/view.h
app_demo_CPPFLAGS = ... # include directories here
app_demo_LDFLAGS = ... # libraries and library search paths
endif
That's my top-level Makefile.am and as you can see, demoapp folder has all the sources for the demo app and two Objective-C files: main.mm and AppDelegate.m.
However, when I try to run make app-demo, I'm getting this:
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
Which means (and I confirm it from the make logs) that main.mm hasn't been compiled, neither linked.
Does anyone knows workarounds for this?
I don't think this is enough information to debug the problem.
I think automake supports ObjC++. Do you get errors when invoking automake? Does your configure.ac invoke AC_PROG_OBJCXX? If you try compiling the files by hand, does it work?
Resolved by defining separate target in Makefile.am like this:
.mm.o :
$(OBJCXX) -x objective-c++ -c #DEFS# $(CPPFLAGS) $(app_demo_CPPFLAGS) $< -o $#
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.
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.)