How CYGWIN relates to the C: drive - file

I want to understand how the downloaded application of Cygwin relates to the "heart"/"mind" of my system. Yes, I am as green as the Emerald Isles. So, please spare me. Let me give an explanation of the chain of events and my perception of them ("backstory"), so that the motivation for my question can be understood.
Currently, on Cygwin, I can see that it "sees" QUARKy (my [super]username on this comp]. And currently I can see that it (Cygwin) cannot "see" the files contained therein (So there's a, metaphorically speaking: "cognitive dissonance"; somehow it automatically "knows" of QUARKy." yet, it knows nothing of it!). It looks blank when I do the "ls" command when in that directory.
Now, if my memory serves me-- I could swear last time, the FIRST time, I downloaded Cygwin (I had to do a... whatever the appropriate terminology for a "master reset" for a comp. is) I could go into that directory and I could see all of my files-- just like if how it would look to me if I went about accessing the files more conventionally (Do you say "Through a GUI"?). I don't recall doing anything in particular to enable myself to have these privileges.
So, in part, I wonder if I failed to download a package the second time which I had the first. I am certainly having much trouble with the packages this second time around.
I am also wondering if-- though I could swear I am vividly recalling actual experiences of mine-- I am wrong that I ever had such an ability. Therefore, I wonder what "special thing" needs to be done so that Cygwin can see the files contained in this user directory. And I would please like it explained to me how the added special feature enables this privileged. I do see that it should make sense that, having independently downloaded this environment, it should not "naturally" know anything about my comp. But then, it is further striking, I think, that it should know of "QUARKy" and make it a directory. Though, perhaps I place too much weight on this last feature. Afterall, it is just a name and might natural default to making it a directory. Why stop there though?
See how maddening this is for me?!!!
:-( <---- That's what I look like, from now on.
Please help!

Cygwin is not an isolated environment like for example a virtual machine inside VirtualBox. It works on the same filesystem as other Windows applications. Its files could be accessed through any file manager (e.g: Total Commander), and it can access any other file including your home folder in Windows.
Only one thing makes confusion: cygwin uses UNIX-like paths but Windows uses DOS paths. There is a translation method to convert them vica-versa. cygpath utility can do this translation automatically, but it could be done by head as well. Here is some example:
#############################################
# converting to Windows path format:
#############################################
$ cygpath --windows /
C:\cygwin
$ cygpath --windows /home
C:\cygwin\home
$ cygpath --windows /home/username
C:\cygwin\home\username
$ cygpath --windows /cygdrive/c
C:\
#############################################
# converting to Cygwin (UNIX) path format:
#############################################
$ cygpath --unix 'C:\Users\username'
/cygdrive/c/Users/username
$ cygpath --unix 'C:\Windows'
/cygdrive/c/Windows
$ cygpath --unix 'D:\Games'
/cygdrive/d/Games

Related

Can't run SDL2 executable by double-click

Hello :)
I am presently learning SDL2, and I made several programs with it.
With these programs, when I double-click on the executable, the program launches, and everything is okay.
On the last program I made, it doesn't work anymore. With this one, I can only launch from terminal.
The exe has the permissions, so theres no reason for this to happen...
The only thing I changed is that the old generic function file I used (for things like "loadTextureFromImage()"...) to a dynamic library I created. Here's a link to the entire project (just a white window for now) -> RightHere.
I'm currently running Ubuntu 14.04.
If you have any idea on why it doesn't work just for THIS project, tell me please!
Thank you in advance ;)
PS : Here's a project that actually works -> RightHere
PS2 : The projects are in c
Okay, so I did ldd ./myprog, and the libraries linked are where I put them, in "${HOME}/lib". If I understood well, you are telling me that because these libraries aren't in "/usr/lib and so on...", they won't be found, and I should write a script. There's a little thing I forgot to tell : I had to add an environment variable in my .bashrc -> export LD_LIBRARY_PATH=${HOME}/lib, so that the libraries are found at compile-time. Because of what you said, I think that this variable is only loaded in terminals, isn't it? So I tried two scripts :
#!/bin/bash
LD_LIBRARY_PATH=$PWD
./myprog
(like you told) and
#!/bin/bash
LD_LIBRARY_PATH=${HOME}/lib
./myprog
(like I made in my .bashrc).
When I run them by double-clicking on them, neither work.
But, when I run them from terminal, only the second one works.
Thank you for the answer, hope it'll help...
EDIT : I confirm that the variable set in .bashrc are only loaded in terminals : I tested this script ->
#!/bin/bash
echo $LD_LIBRARY_PATH > Run.log
LD_LIBRARY_PATH=${HOME}/lib
echo $LD_LIBRARY_PATH >> Run.log
./Pong
and, when I run it from terminal, Run.log contains this :
/home/yohan/lib
/home/yohan/lib,
but, when I run it from double-click, it only contains
*newline*
/home/yohan/lib
Add export before your variable setting. – keltar
Okay so thank you VERY much, it works now, with this script :
#!/bin/bash
export LD_LIBRARY_PATH=${HOME}/lib
./myprog

C to NASM conversion

I'm trying to find a way to convert simple C code to NASM assembly. I have tried using objconv and downloaded and unzipped and built it since I am using a MAC; however, it doesn't seem to be working. I keep getting "-bash: objconv: command not found". Does anyone know another way or can help me solve the -bash error.
Bash is the program that takes the words you type in a terminal and launches other programs. If it is reporting an error, it is because it cannot find the program you want to run (at least in this case).
You need to either find a pre-packaged installation of objconv, or you need to do the work to "integrate" your copy of objconv yourself.
If you can identify the executable you want to run (probably called objconv) you need to add that to your path. The easiest way (if it is just for you) is to verify that your ~/.bashrc or ~/.bashprofile has a line that looks something like
PATH=$PATH:${HOME}/bin
Don't worry if it doesn't look exactly the same. Just make sure there's a ${HOME}/bin or ~/bin (~ is the short version of ${HOME}).
If you have that then type the commands
cd ~/bin
ln -fs ../path/to/objconv
and you will create a soft link (a type of file) in your home binary directory, and the program should be available to the command line.
If you create the file, and nothing above has any errors, but it is not available to the command line, you might need to set the executable bit on your "real" (not link) copy of objconv.
If this doesn't work, by now you should be well primed for a better, more specific question.
If you have gcc installed, try gcc -masm=intel -S source.c to generate assembly files in a syntax very similar to that of MASM.

C - program compiling, but unable to provide arguments

I'm on a Mac and in terminal I'm compiling my program
gcc -Wall -g -o example example.c
it compiles (there are no errors), but when I try to provide command line arguments
example 5 hello how are you
terminal responds with "-bash: example: command not found"
how am supposed to provide the arguments I want to provide after compiling?
Run it like this with path:
./example 5 hello how are you
Unless the directory where the example binary is part of the PATH variable, what you have won't work even if the binary you are running is in the current directory.
It is not a compilation issue, but an issue with your shell. The current directory is not in your PATH (look with echo $PATH and use which to find out how the shell uses it for some particular program, e.g. which gcc).
I suggest testing your program with an explicit file path for the program like
./example 5 hello how are you
You could perhaps edit your ~/.bashrc to add . at the end of your PATH. There are pro and conses (in particular some possible security issues if your current directory happens to be sometimes a "malicious" one like perhaps /tmp might be : bad guys might put there a gcc which is a symlink to /bin/rm so you need to add . at the end of your PATH if you do).
Don't forget to learn how to use a debugger (like gdb). This skill is essential when coding in C (or in C++). Perhaps consider also upgrading your gcc (Apple don"t like much its current GPLv3 license so don't distribute the recent one; try just gcc -v and notice that the latest released GCC is today 4.8.1).
./example 5 Hello how are you is the syntax you're looking for.
This article lends a good explanation as to why this is important.
Basically, when you hit Enter, the shell checks to see if the first set of characters is an absolute path. If it's not, it checks the PATH variable to find executables with the name of the command you are trying to run. If it's found, it will be run, but otherwise it will crash and burn and you will become very sad.

How to find the callers and callee of a function in C code in vi/vim?

I want to know how can I easily click (or maybe use some easy shortcuts) on a function name and find all its callee or open where it has been defined. Most of the web manuals in web are really hard to follow or don't happen to work out. Say I want to click on allocuvm and see where it has been defined?
uint newstk=allocuvm(pgdir, USERTOP-PGSIZE, USERTOP);
cscope minimal example
Ingo mentioned it, here is an example.
First you should set on your .vimrc:
set cscopequickfix=s-,c-,d-,i-,t-,e-
Then to the base directory of your project and run:
cscope -Rb
This generates a cscope.out file which contains the parsed information. Generation is reasonably fast, even for huge projects like the Linux kernel.
Open vim and run:
:cs add cscope.out
:cs find c my_func
c is a mnemonic for callers. The other cscope provided queries are also possible, mnemonics are listed under:
help cscope
This adds a list of the callers to the quickfix list, which you can open with:
:copen
Go to the line that interests you and hit enter to jump there.
To find callers of the function name currently under the cursor, add to your .vimrc:
function! Csc()
cscope find c <cword>
copen
endfunction
command! Csc call Csc()
and enter :Csc<enter> when the cursor is on top of the function.
TODO:
do it for the current function under cursor with a single command. Related: Show function name in status line
automatically add the nearest database (parent directories) when you enter a file: how to auto load cscope.out in vim
interactively open the call graph like Eclipse. Related: Generate Call-Tree from cscope database
A word of advice: I love vim, but it is too complicated for me to setup this kind of thing. And it does not take into account classes e.g. in C++. If a project matters enough to you, try to get the project working on some "IDE". It may involve some overhead if the project does not track the IDE configuration files (which are auto-changing blobs that pollute the repo...), but it is worth it to me. For C / C++, my favorite so far was KDevelop 4.
For that, Vim integrates with the cscope tool; see :help cscope for more information.
vi / . --- / is the search function in vi, and . will repeat the same command.
you could also use sed ( stream editor ) if it is a large file
sed
grep can get you the line numbers
read the man page

Beginner Doing K&R

I'm just starting programming and going through K&R to try and learn C. I've gotten to the section on command line arguments (5.10) but now I'm stumped. Every time I try and open a program I've written with command line arguments I'm told that file X, X being the argument, doesn't exist.
`gcc -o find find.c
open find test
The file /Documents/Learning_C/test does not exist.`
Any suggestions? Thanks
What system are you on? In Unix/Linux you compile & run your executable via:
gcc -o find find.c
./find test
As others have noted, when you prefix your binary with "./", there wont be any naming conflicts. However, if you made find accessible in your $PATH, you might have some conflicts with find and test--standard programs with most *nix distributions... Maybe you could choose more specific names (i.e. ./myFind testArg)
Try giving your output executable a different name.
I suspect your executing the system find command which is looking for a directory called 'test'.
Or try forcing it by executing
./find toto
Edit: Prepending the ./ to the command is important because it tells the shell to execute the find in the current directory as opposed to the first 'find' that exists in your PATH. It is normally recommended that you don't have . (the current directory) in your PATH for security reasons.
HTH
P.S. Forgot to say good one for working through K&R. I just finished doing the same after working in C for thirty years and it was good to get back and refresh the mind!
Instead of making us all individually guess what exactly you're doing wrong, perhaps you should paste the program you're using for the illustration mentioned ?

Resources