User forums > Using Code::Blocks

must add a file to my project [SOLVED]

(1/2) > >>

bbd:
Hello friends.
Im coping with a strange issue. I've built a project with several libraries. One of them is composed of 2 files let's say toto.h and toto.cpp. I must add the file toto.cpp to my project to make the project build correctly. If not it raises an error about unedfined reference about the arguments of a function defined in toto.cpp. Obviously there was an include pointing to the file and search paths set correctly.
For the other lib I don't need to add the files to my project . the includes are enough.

Miguel Gimenez:
You must compile the library separately and then link with the generated toto.a.

When reporting compilation problems you must always attach a full rebuild log in code tags, see:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

bbd:
thks

In my project I must include a source file named shader.cpp/shader.hpp

I added :
#include <shader.hpp>

when I compile, the file is found but an error is raised :

||=== Build: Debug in tuto5 (compiler: GNU GCC Compiler) ===|
C:\msys64\mingw64\bin\..\lib\gcc\x86_64-w64-mingw32\9.2.0\..\..\..\..\x86_64-w64-mingw32\bin\ld.exe: obj\Debug\tutorial05_textured_cube\tutorial05.o||in function `main':|
C:\Users\.......\Desktop\ogl-master\tutorial05_textured_cube\tutorial05.cpp|67|undefined reference to `LoadShaders(char const*, char const*)'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

the call to the function LoadShaders is correct in my main as it is :
GLuint programID = LoadShaders( "TransformVertexShader.vertexshader", "TextureFragmentShader.fragmentshader" );

I just need to add the file shader.cpp to my project in the managment window and it compiles correctly.

Can you explain me what was going on please ?

Miguel Gimenez:
This is not a full rebuild log, and it does not show the compiler command line. Also, you have not used code tags. Have you read the link I gave you?

You must add the code in shader.cpp to the project using one of these methods:
  - just adding it to the project. As you have seen, this works.
  - creating a library contaning the code in shader.cpp (say shader.a) and linking it to your code using the project's linker options

bbd:

--- Code: --- Clean: Debug in tuto7 (compiler: GNU GCC Compiler)---------------

Cleaned "tuto7 - Debug"

-------------- Build: Debug in tuto7 (compiler: GNU GCC Compiler)---------------

g++.exe -Wall -g -IC:\Users\\Desktop\ogl-master\common -IC:\Users\\Desktop\ogl-master\external\glm-0.9.7.1 -IC:\msys64\mingw64\include\GL -IC:\msys64\mingw64\include -IC:\newton-dynamics-master\sdk\dgNewton -c C:\Users\\Desktop\ogl-master\common\controls.cpp -o obj\Debug\common\controls.o
g++.exe -Wall -g -IC:\Users\\Desktop\ogl-master\common -IC:\Users\\Desktop\ogl-master\external\glm-0.9.7.1 -IC:\msys64\mingw64\include\GL -IC:\msys64\mingw64\include -IC:\newton-dynamics-master\sdk\dgNewton -c C:\Users\\Desktop\ogl-master\common\objloader.cpp -o obj\Debug\common\objloader.o
g++.exe -Wall -g -IC:\Users\\Desktop\ogl-master\common -IC:\Users\\Desktop\ogl-master\external\glm-0.9.7.1 -IC:\msys64\mingw64\include\GL -IC:\msys64\mingw64\include -IC:\newton-dynamics-master\sdk\dgNewton -c C:\Users\\Desktop\ogl-master\common\texture.cpp -o obj\Debug\common\texture.o
g++.exe -Wall -g -IC:\Users\\Desktop\ogl-master\common -IC:\Users\\Desktop\ogl-master\external\glm-0.9.7.1 -IC:\msys64\mingw64\include\GL -IC:\msys64\mingw64\include -IC:\newton-dynamics-master\sdk\dgNewton -c C:\Users\\Desktop\ogl-master\tutorial07_model_loading\tutorial07.cpp -o obj\Debug\tutorial07.o
g++.exe -LC:\msys64\mingw64\lib -o bin\Debug\tuto7.exe obj\Debug\common\controls.o obj\Debug\common\objloader.o obj\Debug\common\texture.o obj\Debug\tutorial07.o  -lOpenGL32 -lglu32 -lfreeglut -lglew32 -lglew32mx -lglfw3dll  C:\msys64\mingw64\lib\libfreeglut_static.a C:\msys64\mingw64\lib\libfreeglut.a C:\msys64\mingw64\lib\libglfw3.a
C:\Users\\Desktop\ogl-master\common\texture.cpp: In function 'GLuint loadDDS(const char*)':
C:\Users\\Desktop\ogl-master\common\texture.cpp:167:15: warning: unused variable 'components' [-Wunused-variable]
  167 |  unsigned int components  = (fourCC == FOURCC_DXT1) ? 3 : 4;
      |               ^~~~~~~~~~
C:\Users\\Desktop\ogl-master\tutorial07_model_loading\tutorial07.cpp: In function 'int main()':
C:\Users\\Desktop\ogl-master\tutorial07_model_loading\tutorial07.cpp:98:7: warning: unused variable 'res' [-Wunused-variable]
   98 |  bool res = loadOBJ("cube.obj", vertices, uvs, normals);
      |       ^~~
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: obj\Debug\tutorial07.o: in function `main':
C:/Users//Desktop/ogl-master/tutorial07_model_loading/tutorial07.cpp:83: undefined reference to `LoadShaders(char const*, char const*)'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
2 error(s), 2 warning(s) (0 minute(s), 1 second(s))
 
--- End code ---

I'm not buiding a library just trying to include a file. I Believed adding the instruction #include and set a path to the file was enough. That is not enough ?

In my main I have several includes. For instance :


--- Code: ---...
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <shader.hpp>
...
--- End code ---

for example I don't need to add the file glm.cpp in my project unlike shader.cpp

Navigation

[0] Message Index

[#] Next page

Go to full version