Author Topic: Problems with libraries and header files  (Read 4921 times)

Offline vahalia

  • Multiple posting newcomer
  • *
  • Posts: 14
Problems with libraries and header files
« on: March 25, 2021, 02:10:55 am »
I am using CodeBlocks with mingw-64 to compile a C/C++ program that uses the GNU Scientific Library (gsl).
I downloaded the binary distribution of gsl and put it in a separate directory from my application code.
Then I went into CodeBlocks, and changed Settings->Compiler->Global Compiler Settings->Search Directories and also Project->Build Options->Compiler->Search Directories to add the path to the gsl's include directory.
I have set the Compiler to GNU GCC Compiler.
I have a mix of C and C++ files. When I build, the new include path is picked up for the C++ files (which use g++.exe) but not by the C files (which use gcc.exe).
I don't find anything in the Settings to specify include directories for C files separately from C++ files.
Any suggestions? Below is my build log:

flex -oE:\SoftwareDev\dealer/calc.scanner.c E:\SoftwareDev\dealer\calc.l
g++.exe -Wall -fexceptions -g -std=gnu++17 -IE:\SoftwareDev\mingw-w64-x86_64-gsl-2.6-1-any.pkg\mingw64\include\gsl -IE:\SoftwareDev\mingw-w64-x86_64-gsl-2.6-1-any.pkg\mingw64\include\gsl -IE:\SoftwareDev\mingw-w64-x86_64-gsl-2.6-1-any.pkg\mingw64\include\gsl -c E:\SoftwareDev\dealer\fnscpp.cpp -o obj\Debug\fnscpp.o
gcc -Wall -fexceptions -g -c E:\SoftwareDev\dealer\random.c -o obj\Debug\random.o
g++.exe  -o bin\Debug\dealer.exe obj\Debug\ABsearch.o obj\Debug\ABstats.o obj\Debug\calc.parser.o obj\Debug\calcScores.o obj\Debug\CalcTables.o obj\Debug\csvparser.o obj\Debug\dds.o obj\Debug\dealerIO.o obj\Debug\DealerPar.o obj\Debug\fnscpp.o obj\Debug\hands.o obj\Debug\Init.o obj\Debug\LaterTricks.o obj\Debug\main.o obj\Debug\master.o obj\Debug\Moves.o obj\Debug\oneDeal.o obj\Debug\Par.o obj\Debug\PBN.o obj\Debug\PlayAnalyser.o obj\Debug\QuickTricks.o obj\Debug\random.o obj\Debug\Scheduler.o obj\Debug\SolveBoard.o obj\Debug\SolverIF.o obj\Debug\Stats.o obj\Debug\Timer.o obj\Debug\tnode.o obj\Debug\translations.o obj\Debug\TransTable.o  -static-libstdc++ -static-libgcc -static 
E:\SoftwareDev\dealer\random.c:6:10: fatal error: gsl_rng.h: No such file or directory
 #include "gsl_rng.h"

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Problems with libraries and header files
« Reply #1 on: March 25, 2021, 08:19:43 am »
Quote
Then I went into CodeBlocks, and changed Settings->Compiler->Global Compiler Settings->Search Directories
Not the best idea... it is always better to do this in the project settings, as you did.

Quote
Project->Build Options->Compiler->Search Directories
Make sure that you set the directories on a project level. Select the project name on the left before modifying the options

Where is on your file system?
Code
gsl_rng.h


Ps, please use code tags for logs (the # symbol in the forum post editor).

Offline vahalia

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Problems with libraries and header files
« Reply #2 on: March 25, 2021, 08:49:52 pm »
The gsl_rng.h file is in the directory E:\SoftwareDev\mingw-w64-x86_64-gsl-2.6-1-any.pkg\mingw64\include\gsl.
I tried various combinations of project settings and global compiler settings, to no avail.
In the log, we can see that the -I directives are present in the g++ lines but missing in the gcc lines.
Seems g++ and gcc are picking up the parameters from different places, and the project settings are only impacting the g++ settings.
(Hope I have posted the log correctly this time. A little new to this forum.)

Code
g++.exe -Wall -fexceptions -g -std=gnu++17 -IE:\SoftwareDev\mingw-w64-x86_64-gsl-2.6-1-any.pkg\mingw64\include\gsl -IE:\SoftwareDev\mingw-w64-x86_64-gsl-2.6-1-any.pkg\mingw64\include\gsl[/color] -IE:\SoftwareDev\mingw-w64-x86_64-gsl-2.6-1-any.pkg\mingw64\include\gsl -c E:\SoftwareDev\dealer\fnscpp.cpp -o obj\Debug\fnscpp.o
gcc -Wall -fexceptions -g -c E:\SoftwareDev\dealer\random.c -o obj\Debug\random.o
...
E:\SoftwareDev\dealer\random.c:6:10: fatal error: gsl_rng.h: No such file or directory
#include "gsl_rng.h"
« Last Edit: March 25, 2021, 08:51:35 pm by vahalia »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Problems with libraries and header files
« Reply #3 on: March 26, 2021, 09:57:33 am »
You are mixing c and c++ files. Codeblocks decides with the file ending what compiler should be called.
Stick to the cpp file ending and you should be good.

[Edit:] Still there seems to be a bug in codeblocks that it does not use the project options for different compilers. I remember to have found this bug some time ago, but fixing it is ultra hard...
« Last Edit: March 26, 2021, 10:01:49 am by BlueHazzard »

Offline vahalia

  • Multiple posting newcomer
  • *
  • Posts: 14
Re: Problems with libraries and header files
« Reply #4 on: March 27, 2021, 02:43:33 am »
Thanks. I do need to mix c and cpp files, since I am calling the gsl library, which does not seem to support C++.
Anyway, I figured out a solution.
Under Settings -> Compiler -> Other Settings -> Advanced Options -> Commands -> Command, we can specify the command syntax to use for different extensions.
Seems the default setting for C files was missing "$options $includes". (These parameters were present in the default setting for C++ files.)
I added this manually and everything worked just fine.
Thanks much for your help.