Author Topic: Invalid argument when I include boost headers and link with boost libraries  (Read 8075 times)

Offline ericjoe

  • Multiple posting newcomer
  • *
  • Posts: 11
Hi I am setting up Boost with Code::Blocks in Windows.

At the moment, I am at including boost headers and linking with boost libraries step. Refer to http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef#Add_Boost_to_an_existing_project_in_Code%3a%3aBlocks

I do not quite understand the statement in that website:
Quote
For example, use "#include <boost/filesystem.hpp>", "boost_filesystem-mgw45-mt-1_47" and "boost_system-mgw45-mt-1_47" to use boost.filesystem.

settings compiler & debugger linker settings add

examples: (order does matter) F:\CodeBlocks\lib\libboost_regex-mgw44-1_51.a F:\CodeBlocks\lib\libboost_thread-mgw44-mt-1_51.a F:\CodeBlocks\lib\libboost_chrono-mgw44-1_51.a f:\codeblocks\lib\*.a

From that statement above, I tried to add
Code
..\..\..\Program Files\CodeBlocks\lib\lib*.a
in the Project Build Options -> Linker settings


Then I click "Build and Run" and receive an error message from the "Build log".
Code
-------------- Build: Debug in MERIT (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -L..\..\..\boost_1_47_0\libs -o bin\Debug\MERIT.exe obj\Debug\Calcs.o obj\Debug\Cam2.o obj\Debug\CongestedArea.o obj\Debug\CopyProtection.o obj\Debug\DatabaseIO.o obj\Debug\ErrorReporting.o obj\Debug\EventTree.o obj\Debug\ExcelInputParser.o obj\Debug\Explosion.o obj\Debug\Grid.o obj\Debug\GridArea.o obj\Debug\GridPoint.o obj\Debug\IgnitionArea.o obj\Debug\ImageWriter.o obj\Debug\Logger.o obj\Debug\Metreology.o obj\Debug\PopulationArea.o obj\Debug\QRAModel.o obj\Debug\ReceiverArea.o obj\Debug\Simulation.o obj\Debug\sqlite3.o obj\Debug\Utilities.o obj\Debug\WorkerGroup.o   -lboost_*-mgwXX-mt-1_47 "..\..\..\Program Files\CodeBlocks\lib\lib*.a" "C:\Program Files\CodeBlocks\lib*.a"
mingw32-g++.exe: error: C:\Program Files\CodeBlocks\lib*.a: Invalid argument
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

I suspect the problem comes from "mingw32-g++.exe: error: C:\Program Files\CodeBlocks\lib*.a: Invalid argument"

However I could not find which setting in Code Blocks has "C:\Program Files\CodeBlocks\lib*.a"

Another observation I would like to mention is when I right click on a code and choose "Open #include <boost/algorithm/string.hpp>",


I got an error message saying below:


Does this error message relate to my problem above?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Did you self-build the Boost Libraries?
If not, where did you find pre-built Boost Libraries?

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
This field in the ui doesn't support wildcards (the * character). You have to add all libs manually.

Also don't add them with the full path, but only use the file name.
You'll also have to strip the lib prefix and .a extension.
And finally you'll have to set a linker search path.

(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline ericjoe

  • Multiple posting newcomer
  • *
  • Posts: 11
This field in the ui doesn't support wildcards (the * character). You have to add all libs manually.
Also don't add them with the full path, but only use the file name.
You'll also have to strip the lib prefix and .a extension.

I have updated the "Linker Settings" and removed wildcards (the * character) and deleted lib prefix and .a extension.

You may refer to the image below:


However, I do not understand your statement below:
Quote
And finally you'll have to set a linker search path.

I have done some settings in "Project Build Options" -> "Search directories" -> "Compiler". (Please refer to the image below.)


and also in "Project Build Options" -> "Search directories" -> "Linker"


When I "Build and run", I got the error message as shown below:
Code
-------------- Build: Debug in MERIT (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -L"..\..\..\Program Files\CodeBlocks\lib" -L..\..\..\boost_1_47_0\libs -o bin\Debug\MERIT.exe obj\Debug\Calcs.o obj\Debug\Cam2.o obj\Debug\CongestedArea.o obj\Debug\CopyProtection.o obj\Debug\DatabaseIO.o obj\Debug\ErrorReporting.o obj\Debug\EventTree.o obj\Debug\ExcelInputParser.o obj\Debug\Explosion.o obj\Debug\Grid.o obj\Debug\GridArea.o obj\Debug\GridPoint.o obj\Debug\IgnitionArea.o obj\Debug\ImageWriter.o obj\Debug\Logger.o obj\Debug\Metreology.o obj\Debug\PopulationArea.o obj\Debug\QRAModel.o obj\Debug\ReceiverArea.o obj\Debug\Simulation.o obj\Debug\sqlite3.o obj\Debug\Utilities.o obj\Debug\WorkerGroup.o   -lboost_chrono-mgw47-mt-1_47 -lboost_chrono-mgw47-mt-d-1_47 -lboost_date_time-mgw47-mt-1_47 -lboost_date_time-mgw47-mt-d-1_47 -lboost_exception-mgw47-mt-1_47 -lboost_exception-mgw47-mt-d-1_47 -lboost_filesystem-mgw47-mt-1_47 -lboost_filesystem-mgw47-mt-d-1_47 -lboost_graph-mgw47-mt-1_47 -lboost_graph-mgw47-mt-d-1_47 -lboost_iostreams-mgw47-mt-1_47 -lboost_iostreams-mgw47-mt-d-1_47 -lboost_math_c99f-mgw47-mt-1_47 -lboost_math_c99f-mgw47-mt-d-1_47 -lboost_math_c99l-mgw47-mt-1_47 -lboost_math_c99l-mgw47-mt-d-1_47 -lboost_math_c99-mgw47-mt-1_47 -lboost_math_c99-mgw47-mt-d-1_47 -lboost_math_tr1f-mgw47-mt-1_47 -lboost_math_tr1f-mgw47-mt-d-1_47 -lboost_math_tr1l-mgw47-mt-1_47 -lboost_math_tr1l-mgw47-mt-d-1_47 -lboost_math_tr1-mgw47-mt-1_47 -lboost_math_tr1-mgw47-mt-d-1_47 -lboost_prg_exec_monitor-mgw47-mt-1_47 -lboost_prg_exec_monitor-mgw47-mt-d-1_47 -lboost_program_options-mgw47-mt-1_47 -lboost_program_options-mgw47-mt-d-1_47 -lboost_random-mgw47-mt-1_47 -lboost_random-mgw47-mt-d-1_47 -lboost_regex-mgw47-mt-1_47 -lboost_regex-mgw47-mt-d-1_47 -lboost_serialization-mgw47-mt-1_47 -lboost_serialization-mgw47-mt-d-1_47 -lboost_signals-mgw47-mt-1_47 -lboost_signals-mgw47-mt-d-1_47 -lboost_system-mgw47-mt-1_47 -lboost_system-mgw47-mt-d-1_47 -lboost_test_exec_monitor-mgw47-mt-1_47 -lboost_test_exec_monitor-mgw47-mt-d-1_47 -lboost_unit_test_framework-mgw47-mt-1_47 -lboost_unit_test_framework-mgw47-mt-d-1_47 -lboost_wave-mgw47-mt-1_47 -lboost_wave-mgw47-mt-d-1_47 -lboost_wserialization-mgw47-mt-1_47 -lboost_wserialization-mgw47-mt-d-1_47 "C:\Program Files\CodeBlocks\lib*.a"
mingw32-g++.exe: error: C:\Program Files\CodeBlocks\lib*.a: Invalid argument
Process terminated with status 1 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

I suspect the error comes from "mingw32-g++.exe: error: C:\Program Files\CodeBlocks\lib*.a: Invalid argument".

Another update I would like to state is when I right click on a code and choose "Open #include <boost/algorithm/string.hpp>", I could open "string.hpp" in Code Block.

I have included the screenshot for "Settings" -> "Global variables..."


Could you suggest how can I resolve the error above? Thank you.

Offline ericjoe

  • Multiple posting newcomer
  • *
  • Posts: 11
Did you self-build the Boost Libraries?
If not, where did you find pre-built Boost Libraries?

Tim S.

Hi Tim, I followed the instruction from http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef

After I downloaded Boost, I built it by following the steps shown in "Build Boost" from the website above.

The Boost Libraries are found in "C:\Program Files\CodeBlocks\lib"


Do you refer to that folder?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Check the setting for each target.
The left column you have the project highlighted; highlight each target (one at a time) and check their settings.

Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ericjoe

  • Multiple posting newcomer
  • *
  • Posts: 11
Check the setting for each target.
The left column you have the project highlighted; highlight each target (one at a time) and check their settings.

Tim S.

Hi Tim,

I have checked the settings (Linker Settings, and Search directories -> Compiler and Linker) on each highlighted target (Debug, Release, Linux, Win32), each of them are empty.

What should I do with the Linker Settings, Search directories -> Compiler and Linker?

Should I follow what I have done for those settings when the Project Name (most top word) at the left column is highlighted?

Thank you

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Check the setting for each target.
The left column you have the project highlighted; highlight each target (one at a time) and check their settings.

Tim S.

Hi Tim,

I have checked the settings (Linker Settings, and Search directories -> Compiler and Linker) on each highlighted target (Debug, Release, Linux, Win32), each of them are empty.

What should I do with the Linker Settings, Search directories -> Compiler and Linker?

Should I follow what I have done for those settings when the Project Name (most top word) at the left column is highlighted?

Thank you

Code
mingw32-g++.exe: error: C:\Program Files\CodeBlocks\lib*.a: Invalid argument

You have to find out where you put the setting that caused the error you reported!

Edit: You may have passed the linker setting in the Global Compiler settings area.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F

Tim S.
« Last Edit: September 15, 2015, 02:47:17 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ericjoe

  • Multiple posting newcomer
  • *
  • Posts: 11
Check the setting for each target.
The left column you have the project highlighted; highlight each target (one at a time) and check their settings.

Tim S.

Hi Tim,

I have checked the settings (Linker Settings, and Search directories -> Compiler and Linker) on each highlighted target (Debug, Release, Linux, Win32), each of them are empty.

What should I do with the Linker Settings, Search directories -> Compiler and Linker?

Should I follow what I have done for those settings when the Project Name (most top word) at the left column is highlighted?

Thank you

Code
mingw32-g++.exe: error: C:\Program Files\CodeBlocks\lib*.a: Invalid argument

You have to find out where you put the setting that caused the error you reported!

Edit: You may have passed the linker setting in the Global Compiler settings area.
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_I_would_like_to_compile_a_project_using_some_non-standard_libraries._How_can_I_indicate_to_CodeBlocks_that_these_libraries_and_include_files_exist.3F

Tim S.

Hi Tim,

Thank you for your hint. I managed to solve the problem.

I have accidentally passed the linker settings in Settings -> Compiler -> (Global compiler settings highlighted at the left column) -> Linker Settings tab.

After I removed the "C:\Program Files\CodeBlocks\lib*.a" in the Linker Settings, when I rebuild, then build and run, the exe file is running.

Thank you once again.