How to compile an program using ncurses static

Mar 20, 2011 at 2:51pm
Hello,

I'm developing my own os from the bottom up (it's based on linux).
I'm using cygwin and windows.
I've got a special cross-compiler (gcc/g++ based) for the compilation for the os (livecd based),
if you use the -static option and the -o init option it compiles so that the kernel can boot it (a simple hello world-program works).

I've finished the gui, it's build in c++ (else i wouldn't post it here) and it works when compiling it normally with g++ (for testing so i don't have to burn the cd a lot).

But when i add the -static option i get the following errors:
$ g++ gui.cpp -lncurses -lform -static
gui.cpp: In function 'int main()':
gui.cpp:52: warning: deprecated conversion from string constant to 'char*'
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status

It's the same with the cross-compiler.

So does anyone know what's causing the errors, and how to solve them?

It would be great is someone could help me!

PS: Does anyone know how to pass an array to an function? EDIT: solved that, convert the array to vector and pass that to the function along with the array length and convert the vector back to array in the function after declaring the empty array with the number of elements passed

Greetings
Last edited on Mar 20, 2011 at 3:09pm
Mar 20, 2011 at 9:51pm
Answer: don't statically link ncurses.



No, really, just don't do it.
Mar 20, 2011 at 10:58pm
PS: Does anyone know how to pass an array to an function? EDIT: solved that, convert the array to vector and pass that to the function along with the array length and convert the vector back to array in the function after declaring the empty array with the number of elements passed


WHA???

why not:
void dosomthing(int randomarray[]) /* as if the function name "dosomthing" wasn't overused */

Read this and thought of you: http://uncyclopedia.wikia.com/wiki/Workaroundoriented_programming
Mar 21, 2011 at 3:22pm
@Duoas:
If i don't generate a static program the kernel gives this message and halts at the point where it should start my gui (wich is also the init program):
1
2
Error: could not start /sbin/init
kernel panic: VFS: init not syncing!

With the following program:
1
2
3
4
5
6
#include <iostream>

int main()
{
std::cout << "Hello!\n";
}

When compiles static it outputs:
1
2
3
4
<a lot of messages from the kernel, but all coming down to: "i'm starting up!">
Hello!
Init successfully executed, shutting down...
<a lot of shutdown messages>

You see why i need to!?
I know why it's needed, if you don't use static it will ask for shared libs whice aren't there (it's part of the programs task to create them).

@king214:
Your idea was the first thing i tried anyway (i've read so many refrences and tuts since the day i started programming, it must have been in one cause it was my first idea).
Sadly it didn't work, an empty array was transmitted, i've also made this demo code for you (it didn't work either):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <stdio>

void print_array(char *array[], int arrlen)
{
// the (int)(arrlen - 1) is to keep the loop from going once to much
// and causing it to print out an non-existing array value causing an "Segmentation Fault"
for (int i = 0; i < (int)(arrlen - 1)
{
std::cout << "Array value " << (int)(i + 1) << ": " << array[i] << "\n";
}
}

int main(void)
{
char *myarray[] = {"Hello,", "I'm an array which was passed to an function!"};
print_array(myarray, 2);
return 0;
}

The code should output this:
1
2
Array value 1: Hello,
Array value 2: I'm an array which was passed to an function! 

But instead it doesn't produce any output!
So i went thinking,
then i had it:
Once i made an webcrawler which uses an array to pass the data to the next function using an scheme like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
page source downloader
        | (not an array, an string containing the unmodified page source)
An spacer (an array is passed to the next function containing everything that was seperated using an space, e.g. if the source is Hello World!, it passes an array with the values array[0] = "Hello" and array[1] = "World!")
        | 
url-filter (this filters every thing other than url's out, meaning it only passes url's found in src/href tags to the next)
       |
domain-filter (removes url's pointing to external domains, url's going to an subdomain of the primary domain we're crawling are permitted)
       |
image-filter (it removes everything what points to images/movies/any other a/v content)
       |
script-filter (this removes any url's to scripts, like the image-filter this wouldn't be needed if i only scanned the href tags, but i need to scan (i)frames to since a lot of sites, including mine, use them)
       |
custom-filter (you can set extensions which you don't want)
      |
page-filter (is part of the custom filter but this one removes pages containing a string in the name that shouldn't be scanned, e.g. login pages)
      |
recent-url-filter (removes url's logged by the follower so it doesn't enter an endless loop)
     |
map-builder (put's it all in a nice diagram and outputs it to file, doesn't modify the array of url's)
     |
link-follower (follows/logs the urls passed to it and restarts the process)

However it didn't work.
So i added a print_array function and set the follower to not follow (so the messages don't disappear in others),
but there was no output (exept for the page source downloader)!
I found out that i can only pass int arrays to functions,
just like with my new project i need to pass text (char */string arrays.
So i (re-)used my old solution to the problem: first convert the array to an vector before passing it on.
Although you are right about the int array, i need to pass an char * array and that doesn't work.
I use ncurses for the gaphics.
I've build an .h file containing self-written function which make a lot of thing faster,
like when i need to open a window containing a menu i use this function:
1
2
3
4
5
6
7
8
// the null at the end is something from ncurses, else it doesn't display a thing
char *choicesa[] = {"a", "b", "c", (char*)NULL,};
// winnum is an int var i use to make sure i don't overwrite anything, and is initialized with val -1 so the first window gets passed 0
winnum++;
// the 1 at the end is an color pair i defined at the init section of the program
// i'm not at home now so i don't have the code i used to convert the array to vector
// there are more options but they are self defining when not passed
show_menu((WINDOW*)win[winnum], x, y, (char*)"Menu Title", choices, 1);

and after right use that code (three lines when comments are stripped) produces an window containing this (i use the box function to create a nicer layout, but this is the best i can to represent it):
1
2
3
4
5
6
| Menu Title |
+-------------+
| * a            |
|    b            |
|    c            |
+-------------+

I've got compareble functions for other things and tricks

So now you know how my system is constructed (there is of course way more backwork and some extra's).

If you wanna know why i'm doing this:
Just because i can, cause it's a nice challenge and without challanges we wouldn't be learning anything and so i can improve my skills and size up my knowlege.

Greetings
Last edited on Mar 21, 2011 at 3:27pm
Mar 21, 2011 at 4:10pm
Um... I hate to rain on your parade, I really do, but I don't think you're nearly skilled/knowledgable enough to get into OS programming.

It's a rather complex field that requires quite a bit of knowledge and skill, both of which I'm not sure if you have, especially judging by the errors in your demo in the last post. Going from where I think you are straight to an OS... that sounds like way too big of a jump.

Maybe... start with something smaller, like an XML parser? :/

Sorry,
-Albatross
Last edited on Mar 21, 2011 at 4:13pm
Mar 22, 2011 at 11:03am
@Albatross
Dude, i'm a c++ programmer for 5 years now!
I've made so many programs that, besides the one i currently use for programming, i have 2 other computer with harddrives full of c++ projects and headers.
After the first pc i decided to put long codes in a central set of headers, so i don't have to gather all that code from so many projects everytime.
I even found a way to crack any password (i modified the program thc-hydra, i put an code in it that produces every possible character combination).

I just wanna make a simple os:
a gui, no complex multitasking and other stuff.
it uses an linux kernel and that part works

So, don't say i don't know what i'm talking about!!!!!!
Mar 22, 2011 at 2:34pm
Dudes,
this may be an bit off topic but i found an article on how to compile an ncurses program static (the guy made some typing errors so make sure you correct them):
http://belsky.info/archives/13-Building-static-executables-on-Linux.html
It worked (with the g++ from cygwin, only producing 2 warnings about an unused definition),
Now the problem is that my cross-compiler gives so many errors that they can't fit in the cygwin window, i think that is because it looks in a diffrent include dir.
Does anyone know an cross-compiles who uses /usr/include for includes and accepts the -I option (my cross-compiles ignores them) and it must be able to run under cygwin and it may not replace the normal g++?

Greetings
Last edited on Mar 22, 2011 at 2:35pm
Mar 22, 2011 at 3:29pm
Again, I'm very sorry. However, the errors in the demo that you implied that you got to compile...
But instead it doesn't produce any output!

...and the question you asked here -> http://cplusplus.com/forum/general/36279/ both suggest that you just don't have enough skill in programming in C++ yet. :(

I don't want to ruin your dream, I just want to save you a bit of a headache by suggesting that you maybe postpone your project? Not give up, just postpone. Trust me, there aren't many things more demotivating than getting into a project that you have large amounts of trouble doing. :/

-Albatross
Last edited on Mar 22, 2011 at 4:07pm
Mar 23, 2011 at 6:38am
Since the topic is solved by the link to the article at belsky.info
And i'm getting tired of albatrosses comments on me:
I'm closing the topic
Topic archived. No new replies allowed.