Author Topic: Adding files to project  (Read 2261 times)

Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Adding files to project
« on: December 18, 2018, 10:21:08 pm »
Hi guys:
   I have some programs I want to execute from my Desktop in Linux. They require loading
Jpeg files. If I don't create a project they will Not run from the Desktop. So, the last few days
I have been trying to figure out how to create a project using Code:Blocks. I have been able
to create the project after some time. My problem seems to be adding files to the project.
When I go to Project - Add Files the window shows up displaying the cbp file. Then I go to
the Directory and pick on my C file and click Open at the bottom. I only get a blank screen.
Evidently this is NOT the proper way to do this. If someone has the time, could you show
the correct way to create the Project and how to load the files in order to compile and link
a program. I have been using Code:Blocks for some time, but never using the project feature.
I would always run my programs from the Directory where the file was located. Now I want
to run them from an Icon on the Desktop. Seems simple but is beyond me how to do this!
Thanks for any help you can offer.

I have switch to version 10.5 Code:Blocks, now I am getting 'Can't read timestamp'.
What is up with that!
« Last Edit: December 21, 2018, 08:17:41 pm by MannyMoe »

Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Adding files to project
« Reply #1 on: December 30, 2018, 04:51:04 pm »
I have finally gotten my project file completed!
Everything looks great. The file runs perfectly as
long as I am still in codeblocks. When I go to Debug
and try to run the executable, the screen blinks and
is turns black. There is still something I am missing
but I do not know what it is! Has anyone got any ideas
why my file will not run? Thanks for any help you can
offer!


Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Adding files to project
« Reply #3 on: December 30, 2018, 08:44:05 pm »
BlueHazzard:

   Thanks for the reply. This is not the problem with my project.
My file depends on hitting the ESC key or clicking the Close
button. Is there any setting in Codeblocks that could be causing
my problem? I have tried version 10.05 and version 13.12 and
both do the same thing. I am using ubuntu 16.04 for this project.
Thanks again.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2379
Re: Adding files to project
« Reply #4 on: December 30, 2018, 09:12:53 pm »
Quote
My file depends on hitting the ESC key or clicking the Close
Ok, now you have to specify more closely what type of application you are making. What framework you are using and what it is loading/doing. Without this information it is hard to help...

From my mind there could be 2 reasons for this behavior
1) Your application can not find some dynamic library and crashes (try to open it in command line, or use the ldd tool to find any missing library, or start it with gdb from outside codeblocks). Remember that codeblocks adds the path to the linked libraries automatically to ?LD_LIBRARY_PATH? before it runs the application.
2) Your application can not find some input file (you mentioned you are using jpg files in your program) and you do not do any proper error handing on file not found. Remember that if you run a program trough codeblocks the search path for external files begins in the project folder and if you run your application from double click the search path for external files starts from the place where the executable is

Generally speaking your application goes in one error mode you are not handling and you get an unexpected exit. This is bad programming and should be avoided. Luckily you have found the problem and can now fix it.

[edit:] You will be amazed how better codeblocks is with version 17.12. Please poke the maintainer of ubuntu to update the codeblocks version...
« Last Edit: December 30, 2018, 09:14:26 pm by BlueHazzard »

Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Adding files to project
« Reply #5 on: December 30, 2018, 10:22:34 pm »
BlueHazzard:

  Thanks again for the reply. I believe this is getting way over my head.
I don't think I can follow what you are saying. I believe this is something
I need to stay away from. I am afraid I will really mess things up! This is
my first time trying to make a project file using codeblocks. I have been
going to the directory and running my programs from there. I thought
it would be nice to be able to run them from the Desktop. I need to learn
much more than I know right now! Thanks again for your time. It is nice
to see that you seem to know a great deal. Have a wonderful day my friend!

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2379
Re: Adding files to project
« Reply #6 on: December 31, 2018, 10:55:25 am »
I do not understand your fear about projects. They are exactly the same as if you build one single file, except that you manage your build a bit.

With all your writing you did not add any information that makes it easier to help you. Instead of whinging about how complicated projects are and how you still have to learn you can simply answer the questions and we will guide you through your problem. It is not rocket science...

To make it even a bit more easier, some checklist you can answer:
1) What library do you use for your user interface? (wxWidgets, GTK, QT...)
1.1) Does this library is linked statically or dynamically?
1.2) How do you installed this library? Was it on the system? Through the packet manager?
2) How do you load the image file?
2.1) What function do you use to load the file
2.2) How do you specify the path to the file you load?
2.3) What do you do if the loading of the file fails?
2.4) Where is the file located? Relative to your executable?

Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Adding files to project
« Reply #7 on: December 31, 2018, 01:36:10 pm »
BlueHazzard:

    I am sorry for some of the things I said! I did not mean any disrespect. I just do
not know how to answer some of your questions. Here are some things that might
help you:

I do not use anything fancy. I only use codeblocks, allegro5 and opengl for my programs.
I use only their functions to load my images. All my programs run perfectly from their
directories. You are correct about the problem being the path to the images. When I load
an image, if I include the absolute path to the image and then compile, link, and copy to
the desktop all is perfect. I know this is not the correct way to do things, but it works.
For the first time in my life I tried to use the Debugger. This is what it reported:
warning: GDB: failed to set controlling terminal: operation not permitted

The last thing I did that really made a difference was to set the working directory to the
place where my programs were located.

All my programs are single files. The only reason to get involved with a project was so I
could run them from my desktop.

As far as static or dynamic. I have no idea.

All the libraries and header files are in their correct place and are working perfectly.

The project file (cbp file) is located in a subdirectory of the working directory.

Hope this helps. I will try to stay calm in order to see this thing done!

Thanks and have a great day!

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2379
Re: Adding files to project
« Reply #8 on: December 31, 2018, 02:24:45 pm »
Quote
    I am sorry for some of the things I said! I did not mean any disrespect
This was not disrespectful to me, but to yourself. You have to have some confidence ;)

Quote
You are correct about the problem being the path to the images.
Great! Now you know how to solve it :)

Quote
GDB: failed to set controlling terminal: operation not permitted
This should be harmless. If you  have other problems during debugging, make sure you enable debug symbols:
Select the "Debug" target from "Build->Select target" and make a rebuild "Build->Rebuild"
Or enable it in the compiler options: Project->build options->Select your project name on the left->Set a tick at the -g flag->hit ok  and rebuild with Build->Rebuild
And if you still have problems please post a full build log and a debugger log from the debugger tab

Quote
Thanks and have a great day!
same to you!

Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Adding files to project
« Reply #9 on: December 31, 2018, 06:37:38 pm »
BlueHazzard:
 
   OK! I did what you said and everything is good. No errors of
any kind! I did run into something the other day I might point
out: LD_LIBRARY_PATH = $LD_LIBRARY_PATH: .
Just a period. I tried to find it again but could not. This may tell
the story right there.
When I went to the Debug directory and clicked on the executable,
same thing again: screen blinks and turns black. I believe that PATH
needs to be corrected but I could not find it.
Also, do I need to upgrade my version of codeblocks or do you think
version 13.12 is ok for what I do?

I might add when I did a rebuild, nothing happened. In checking the
messages, it said everything was up to date. Nothing needed to be done.

Are you one of the developers of codeblocks? Just asking.

Hope all is going well on your end!!!!!!

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2379
Re: Adding files to project
« Reply #10 on: January 01, 2019, 08:26:58 pm »
Quote
Also, do I need to upgrade my version of codeblocks or do you think
version 13.12 is ok for what I do?
13.12 is at least 5(6) years old... updating won't hurt, there where 100s of bugfixes and improvements...

Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Adding files to project
« Reply #11 on: January 01, 2019, 09:00:32 pm »
BlueHazzard:

   I still haven't got this thing to work. How do I static link this project?

   Could that be my problem?

   Still grasping for straws on this.

   Have a great new year!

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2379
Re: Adding files to project
« Reply #12 on: January 03, 2019, 11:41:31 am »
Quote
   I still haven't got this thing to work. How do I static link this project?
Haven't you found out that the paths to your images are the problem?

If still the paths are your problem i cant try to explain to you how paths work with projects:
1) If you program an application and you open a file with fopen("image.jpg"); Your application will search in the same folder as where it is for the file "image.jpg". This is called the "current working directory", cwd in short.
2) If you start this application from codeblocks, codeblocks will set the cwd to the folder where the project file is located. This is done so you can make a release build and a debug build in different folders, but your resources are always at the same place. You can change the cwd in Project->Properties->Execution working directory. Changing this option will not alter the behaviour if you start your application by double clicking on it
3) So if you open a file in your application using relative paths place the resource file in the project directory when starting your application within codeblocks, and put your resource file near to your application if you start it through double click.

To link your library in your application is dependend on your library. This is not specific something about codeblocks
I have googled for 5 sec and found this link:
https://www.allegro.cc/forums/thread/616656
I do not know how you have set up your project and added the libraries, but if you use pkg-config you will have to change the line to following:
Code: [Select]
pkg-config --libs --static allegro-static-5 allegro_image-static-5 allegro_primitives-static-5

How did you installed allegro? If you have used the package manager you do not have a library problem...

Offline MannyMoe

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Adding files to project
« Reply #13 on: January 03, 2019, 09:22:11 pm »
BlueHazzard:

     I have been working everyday for the last (3) weeks and still coming up
with the same thing. Let's review: My project will run perfectly in codeblocks
after I do a build and run. My file will run perfectly when I go to the directory and
double click the file. If I copy the file generated with codeblocks to my Desktop,
the screen will only blink and turn black. If I include the absolute path to my
image file and build and run the file, outside of a project, the file will run perfectly.
This is just a simple file for testing. If only draws a rectangle at the border of the
screen and displays an image in the center of the screen.
      In looking at the .cbp file, it shows adding the libraries (.so files) to the project.
It also shows the .c file and the image file added. I do not know anything else to do.
The fact that it runs by itself adding the absolute path to the image file, proves where
the problem is, but I can't find out why the project file won't run from the Desktop.
Since it doesn't seem to be a library problem, perhaps the static libraries won't work
either. Me thinks I have found a real problem for the books. I am still very calm!!!!
      While I have you here, tell my why that 'main.c' file keeps showing up and how
do I get rid of it? Very annoying to say the least! Have a good day!

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6550
    • My Best Post
Re: Adding files to project
« Reply #14 on: January 03, 2019, 09:30:56 pm »
Try posting a full build log and maybe someone will see a problem to fix!

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

Edit: Attaching your Code::Blocks project file (.cbp) to a post might also help someone help you.

Tim S.
« Last Edit: January 03, 2019, 09:42:41 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org